Cod sursa(job #3159688)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 21 octombrie 2023 19:53:25
Problema Text Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

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

string s;

bool IsLetter (char c) {
    return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
}

int main() {
    getline(fin, s);

    int wordLen = 0;
    int wordCount = 0;
    bool lastWasLetter = false;

    int sum = 0;

    for (char c : s) {
        if (IsLetter(c)) {
            wordLen++;
            lastWasLetter = true;
        }
        else if (lastWasLetter) {
            wordCount++;
            lastWasLetter = false;
        }

    }

    int average = wordLen / wordCount;
    fout << average << '\n';

    return 0;
}