Cod sursa(job #600615)

Utilizator warchildmdMihail Burduja warchildmd Data 2 iulie 2011 17:08:47
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<cstdio>

int main()
{
    FILE *f;
    f = fopen("text.in","r");
    freopen("text.out","w",stdout);
    char c;
    int words = 0;
    int length = 0;
    bool inWord = false;
    while((c = fgetc(f)) && (!feof(f)))
    {
        if(((c>='a')&&(c<='z')) || ((c>='A') && (c<='Z')))
        {
            if(inWord)
            {
                length++;
            }
            else
            {
                words++;
                inWord = true;
                length++;
            }
        }
        else
        {
            if(inWord)
            {
                inWord = false;
            }
        }
    }

    int result = length/words;
    printf("%d\n", result);

    return 0;
}