Cod sursa(job #674973)

Utilizator andreimaresuMaresu Andrei andreimaresu Data 6 februarie 2012 22:37:48
Problema Text Scor 60
Compilator c Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
    FILE *f=fopen("text.in","r"),*p=fopen("text.out","w");
    char *s,*sep,*a;
    int i,l=0,nr=0;
    sep=" 1234567890~`!@#$%^&*()_{}[]|\'><+=\"?:;',.-";
    s=malloc(100000*sizeof(char));
    while(fgets(s,100000,f)!=NULL){
    for(i=0;i<strlen(s);i++)
        if(isalpha(s[i])) l++;
        a=strtok(s,sep);
        if (a!=NULL)   nr++;
        while (a!=NULL)
            {nr++;
            a=strtok(NULL,sep);
            }
        nr=nr-2;
    }
     if(nr>0) fprintf(p,"%d",l/nr);
        else fprintf(p,"0");
     fclose(f);
     fclose(p);
     return 0;
}