Cod sursa(job #2128396)

Utilizator The4EverRadu Catalin-Gabriel The4Ever Data 11 februarie 2018 18:01:40
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream f("text.in");
ofstream g("text.out");

int isLetter(char ch) {
    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
        return 1;
    } else {
        return 0;
    }
}

int main()
{
    char s[50];
    int numar_cuvinte = 0,litere=0;

    f.get(s, 50);

    for(int i = 0; i <= strlen(s)-1; i++) {
        if(isLetter(s[i])) litere++;
        if(( isLetter(s[i]) && !isLetter(s[i+1]) )) {
            numar_cuvinte++;
        }
    }
    if(isLetter(s[strlen(s)])) numar_cuvinte++;

    if(numar_cuvinte)
        g<<litere/numar_cuvinte;
    else g<<0;

    f.close();
    g.close();
    return 0;
}