Cod sursa(job #1717210)

Utilizator Coroian_DavidCoroian David Coroian_David Data 14 iunie 2016 16:01:23
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>

#include <cstdio>

using namespace std;

FILE *f, *g;

bool isADigit(char carachter)
{
    if(carachter >= 'a' && carachter <= 'z')
        return 1;

    if(carachter >= 'A' && carachter <= 'Z')
        return 1;

    return 0;
}

char currentCarachter;

bool inWord;

int totalLetters, totalWords;

int main()
{

    f = fopen("text.in", "r");

    while(fscanf(f, "%c", &currentCarachter) == 1)
    {
        if(isADigit(currentCarachter))
        {
            if(!inWord)
                inWord = 1;

            totalLetters ++;
        }
        else
        {
            if(inWord)
            {
                inWord = 0;

                totalWords ++;
            }
        }
    }

    fclose(f);

    g = fopen("text.out", "w");

    fprintf(g, "%d", totalLetters / totalWords);

    fclose(g);

    return 0;
}