Cod sursa(job #801558)

Utilizator Mihai22eMihai Ionut Enache Mihai22e Data 24 octombrie 2012 18:11:53
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include<stdio.h>
#include<string.h>

using namespace std;

#define MAXL 1500005

int n, i, length, nr;
char S[ MAXL ];

int main()
{
    FILE *f = fopen("text.in", "r");

    fgets(S, MAXL - 2, f);

    fclose(f);

    n = strlen(S) - 2;
    while(i <= n)
    {
        while( (S[i] < 'a' || S[i] > 'z') && (S[i] < 'A' || S[i] > 'Z') && i <= n)
            ++i;
        if( (S[i] >= 'a' && S[i] <= 'z') || (S[i] >= 'A' && S[i] <= 'Z') )
            ++nr;
        while( (S[i] >= 'a' && S[i] <= 'z') || (S[i] >= 'A' && S[i] <= 'Z') )
            ++i, ++length;
    }

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

    if(!nr)
        fprintf(g, "0\n");
    else fprintf(g, "%d\n", (length / nr));

    fclose(g);

    return 0;

}