Cod sursa(job #516403)

Utilizator padreatiAurelian Tutuianu padreati Data 23 decembrie 2010 22:06:39
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <math.h>

using namespace std;

int main() {

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

    char* s = new char[2000001];
    int size = 0;
    int words = 0;
    int total = 0;
    while (true) {
        if (in.getline(s, 2000001) == NULL) break;

        int i = -1;
        while (s[++i] != '\0') {
            char c = s[i];
//            cout << c;
            if (c >= 'A' && c <= 'z') {
                size++;
                continue;
            }
            if (size != 0) {
                words++;
                total += size;
                size = 0;
            }
        }
        if (size != 0) {
            words++;
            total += size;
        }
    }

    out << (words ? ((total - (total % words)) / words) : 0);
    cout << (words ? ((total - (total % words)) / words) : 0);
    return 0;
}