Cod sursa(job #3139100)

Utilizator PetraPetra Hedesiu Petra Data 24 iunie 2023 23:27:19
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int isletter(char c)
{
    return (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
}
char c;
int total = 0, words = 0;
int main()
{
    while (!fin.eof())
    {
        c = fin.get();
        s.push_back(c);
    }
    for (int i = 0; i < s.size(); i++)
    {
        if (!isletter(s[i])) continue;
        int j = i, length = 0;
        for (; j < s.size() && isletter(s[j]); j++)
            length++;
        words++;
        total += length;
        i = j;
    }
    fout << total / words;
    return 0;
}