Cod sursa(job #3338893)

Utilizator parus_majorParus Major parus_major Data 5 februarie 2026 13:11:06
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

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

int cnt_words, last_word_length, total_word_length;

void iterate(char ch) {
    if (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) {
        ++last_word_length;
    } else {
        total_word_length += last_word_length;
        if (last_word_length) {
            ++cnt_words;
        }
        last_word_length = 0;
    }
}

int main()
{
    char ch;
    while (fin.get(ch)) {
        iterate(ch);
    }
    iterate(' ');

    fout << total_word_length / cnt_words;

    return 0;
}