Cod sursa(job #807082)

Utilizator theep0Cruceru Radu theep0 Data 4 noiembrie 2012 05:33:50
Problema Text Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

bool is_letter(char c) {
    c = (int)c;
    return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
}

int main () {
    string word;
    ifstream file_stream;
    file_stream.open("text.in");
    bool counted_extra = true;
    int word_count = 0;
    int total_length = 0;
    int word_length;
    int i, l;

    while (file_stream >> word) {
        word_length = 0;
        for (i = 0, l = word.size(); i < l; ++i) {
            bool il = is_letter(word[i]);
            if (il) {
                counted_extra = false;
                ++word_length;
            }
            if (il == false && i != l - 1 && counted_extra == false) {
                ++word_count;
                counted_extra = true;
            }
        }
        if (word_length) {
            ++word_count;
            total_length += word_length;
        }
    }
    file_stream.close();

    ofstream output_file;
    output_file.open("text.out");
    output_file << total_length / word_count;
    output_file.close();
}