Cod sursa(job #3153779)

Utilizator catalinmarincatalinmarin catalinmarin Data 1 octombrie 2023 11:28:39
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <fstream>
#include <string>
using namespace std;
ifstream fin("text.in");
ofstream fout("text.out");
bool litera(char i){
    return (i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z');
}
int main(){
    string str;
    int litere = 0;
    int cuvinte = 0;
    int pozitie = 0;
    while (fin >> str) {
        pozitie = 0;
        while (pozitie < str.size()) {
            if (pozitie > 0 && litera(str[pozitie - 1]) && !litera(str[pozitie])) {
                cuvinte++;
            }
            while (pozitie < str.size() && !litera(str[pozitie])) {
                pozitie++;
            }
            while (pozitie < str.size() && litera(str[pozitie])) {
                litere++;
                pozitie++;
            }
        }
        if (litera(str[str.size() - 1]))
            cuvinte++;
    }
    if (cuvinte == 0) {
        fout << 0;
    } else {
        fout << litere / cuvinte;
    }
    return 0;
}