Cod sursa(job #2276767)

Utilizator TooHappyMarchitan Teodor TooHappy Data 5 noiembrie 2018 12:10:01
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;
 
ifstream in("text.in");
ofstream out("text.out");

int main() {
    ios::sync_with_stdio(false); in.tie(0); out.tie(0);

    string line;
    int nrChars = 0, nrWords = 0;
    while(getline(in, line)) {
        stringstream ss(line);

        string word;
        while(ss >> word) {
            for(int i = 0; i < (int)word.size(); ++i) {
                if(isalpha(word[i])) {
                    int j = i;
                    bool isWord = false;

                    while(j < (int)word.size() && isalpha(word[j])) {
                        isWord = true;
                        ++nrChars;
                        ++j;
                    }

                    if(isWord) {
                        nrWords++;
                    }

                    i = j - 1;
                }
            }
        }
    }

    out << (nrChars / nrWords) << "\n";

    in.close(); out.close();

    return 0;
}