Cod sursa(job #497211)
#include <fstream>
#include <string>
#define MAX 1000000
using namespace std;
char t[MAX];
int main() {
ifstream f("text.in");
ofstream g("text.out");
int len, i, nrWord = 0, nrLetter = 0;
f.get(t,MAX);
//g << t[strlen(t)-2] << t[strlen(t)-1] << "c" << endl;
len = strlen(t);
i = 0;
while ( i < len ) {
while ( (i < len) && (isalpha(t[i])) ) { //(((t[i] >= 'a') && (t[i] <= 'z')) || ((t[i] >= 'A') && (t[i] <='Z'))) ) {
i++;
nrLetter++;
}
if ( nrLetter > 0 ) nrWord++;
while ( (i < len) && !(isalpha(t[i])) ) { //(!(((t[i] >= 'a') && (t[i] <= 'z')) || ((t[i] >= 'A') && (t[i] <='Z')))) ) {
i++;
}
}
if ( !nrWord )
g << 0;
else
g << nrLetter / nrWord;
return 0;
}