Cod sursa(job #323078)

Utilizator freak93Adrian Budau freak93 Data 10 iunie 2009 17:35:31
Problema Text Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<cstdio>
#include<cstring>
#define maxn 2000007

using namespace std;

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

char x,y;

int i,n,p,k,ok;

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

int main()
{
    fscanf(f,"%c",&x);

    while(!feof(f))
        if(x!=' '&&y)
        {
            if(ch(x))++k;
            fscanf(f,"%c",&x);
        }
        else
        {
            n=0;
            y=x;
            fscanf(f,"%c",&x);
            while(x!=' '&&!feof(f))
            {
                if(ch(x))
                {
                    if(!ch(y))
                        ++n;

                    if(!n) ++n;
                    ++k;
                }

                y=x;
                fscanf(f,"%c",&x);
            }

            if(n) p+=n;
        }

    fprintf(g,"%d\n",k/p);

    fclose(f);
    fclose(g);

    return 0;
}