Cod sursa(job #2591624)

Utilizator beo1980Vlad Beu beo1980 Data 30 martie 2020 20:52:05
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
using namespace std;
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    ifstream f("text.in");
    ofstream g("text.out");

    //string lastword =  new string();

    //read file char by char
    char c;
    int totalWords  =0;
    int totalLen    =0;
    string lastWord = "";
    while(f.get(c)) {
       // cout<<c;
        if (isalpha(c)){
            lastWord+=c;
        }
        else  {
            int len = lastWord.length();

            if (len!=0){ // avoid counting empty strings - happnes when more non ascii in a row
            //end of word here. process the word and reset
                //cout<<lastWord<<" "<<len<<" "<<endl;
                totalWords++;
                totalLen+= len;
                lastWord.clear();
            }
        }
    }
//cout<<totalLen<<" "<<totalWords<<endl;
g<<int (totalLen/totalWords);

}