Cod sursa(job #2672752)

Utilizator SurduTonySurdu Tony SurduTony Data 14 noiembrie 2020 17:37:11
Problema Text Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

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

    char text[1000], *p;
    int nrChar = 0, nrWords = 0;
    fin.get(text, 1000);

    p = strtok(text, " -");
    while (p) {
        bool isWord = false;
        for (int i = 0; i < strlen(p); ++i) {
            if ((p[i] >= 'a' && p[i] <= 'z') || (p[i] >= 'A' && p[i] << 'Z')) {
                nrChar++;
                isWord = true;
            }
        }

        if (isWord) {
            nrWords++;
        }

        p = strtok(NULL, " -");
    }

    fout << nrChar / nrWords;

    return 0;
}