Pagini recente » Cod sursa (job #1471711) | Cod sursa (job #44495) | Cod sursa (job #2192597) | Cod sursa (job #3163997) | Cod sursa (job #639265)
Cod sursa(job #639265)
#include <fstream>
#include <cstring>
using namespace std;
char data[1025];
int main()
{
ifstream fin("text.in");
if(fin.good())
{
fin.getline(data, 1025);
fin.close();
unsigned int nrCuvinte = 0;
unsigned int nrLitere = 0;
if (strlen(data)>0)
{
nrCuvinte++;
for(unsigned int i = 0; i<strlen(data); ++i) // O(n)
{
if(isalpha(data[i])) nrLitere++;
if(data[i]==' ' or data[i]=='!' or data[i]=='?' or data[i]=='.' or data[i]=='-')
{
if(data[i]=='?'and data[i+1]=='!') { ++i; } // Y U NO INCREASE?!
nrCuvinte++;
}
}
ofstream fout("text.out");
fout << (nrLitere/nrCuvinte);
fout.close();
}
}
}