Cod sursa(job #1888114)

Utilizator delia_ioanaCeapa Delia Ioana delia_ioana Data 21 februarie 2017 22:18:16
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

int main() {
    ifstream iFile("text.in");
    freopen("text.out", "w", stdout);

    string input;

    while (true) {
        string x;
        iFile >> x;
        input += x;
        if (iFile.eof())
            break;
        input += " ";
    }

    int word_count = 0, word_len = 0, total_word_len = 0, i = 0;
    bool not_word = true;

    while (i ++ < input.size()) {
        if (input[i] < 'A' || (input[i] > 'Z' && input[i] < 'a') || input[i] > 'z') {
            if (!not_word) {
                word_count ++;
                total_word_len += word_len;
                word_len = 0;
            }

            not_word = true;
        } else {
            not_word = false;

            word_len ++;

            if (i == input.size() - 1) {
                word_count ++;
                total_word_len += word_len;
                word_len = 0;
            }
        }
    }

    iFile.close();
    printf("%d\n", (double)(total_word_len / word_count));

    return 0;
}