Cod sursa(job #2369919)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 6 martie 2019 09:47:20
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("text.in");
ofstream fout("text.out");

bool isAlpha(char c) {
    if( 'a' <= c && 'z' >= c)
        return 1;
    if( 'A' <= c && c <= 'Z')
        return 1;
    return 0;
}

int main()
{
    char c;
    long long int cntword = 0;
    long long int cntchar = 0;
    long long int cntlen = 0;
    bool ok = 0;
    while( fin >> noskipws >> c ) {
        if(isAlpha(c)) {
            ok = 1;
            cntlen++;
        }
        if(!isAlpha(c) && ok != 0) {
            cntword++;
            cntchar += cntlen;
            cntlen = 0;
            ok = 0;
        }
    }
    if(isAlpha(c)) {
        cntword++;
        cntchar += cntlen;
        cntlen = 0;
        ok = 0;
    }

    //cout << cntchar << " " << cntword;

    fout << (cntchar/cntword);

    //cout << "Hello world!" << endl;
    return 0;
}