Cod sursa(job #497250)

Utilizator newbieFMI - Cristina Andrei newbie Data 1 noiembrie 2010 21:49:55
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#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 << endl;
    len = strlen(t);
    i = 0;
    
    /*while ( i < len ) {
        if ( isalpha(t[i]) ) { 
            nrLetter++; 
            if ( i == len - 1 ) 
                nrWord++; 
        }
        else 
            if ((i != 0) && (isalpha(t[i-1]))) nrWord++;
        i++;
    }*/
    
    while ( i < len ) {
          while ( (i < len) && (isalpha(t[i])) ) { 
                i++;
                nrLetter++;
          }
          if ( i > 0 ) nrWord++;
          while ( (i < len) && !(isalpha(t[i])) ) { 
                i++;
          }
    }
    
    if ( !nrWord ) 
        g << 0;
    else {
//        g << "litere : " << nrLetter << endl;
//        g << "cuvinte : " << nrWord << endl;       
        g << nrLetter / nrWord;    
    }
    
    return 0;
}