Cod sursa(job #41706)

Utilizator bvaliValentin Bora bvali Data 28 martie 2007 14:54:59
Problema Text Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 10260
int main(){
    char cuv[MAX], text[MAX];
    unsigned long nrCuv=0, litere=0, i, j=0;
    FILE *fin = fopen("text.in", "r");
    FILE *fout = fopen("text.out", "w");
    while(!feof(fin)){
	fgets(text, MAX, fin);
	for(i=0; i<=strlen(text); i++){
	    if(!isalpha(text[i])){
		if(j){
		    cuv[j] = 0;
		    nrCuv++;
		    litere+=j;
		    j=0;
		}
	    }else{
		cuv[j++] = text[i];
	    }
	}
	if(j){
	    cuv[j] = 0;
	    nrCuv++;
	    litere+=j;
	    j=0;
	}
    }
    if(nrCuv)
	fprintf(fout, "%lu", litere/nrCuv);
    else
	fprintf(fout, "0");
    fcloseall();
    return 0;
}