Cod sursa(job #470178)

Utilizator LP337Lazar Pavel LP337 Data 11 iulie 2010 21:22:18
Problema Text Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
/**
*
*	Info: from Infoarena
*	Title: Text
*	Author: Lazar Pavel
*
**/

#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(){
	FILE *fin = fopen("text.in","r");
	FILE *fout = fopen("text.out","w");
	
	char 	line[80];
	char 	ch;
	
	int  	chars = 0;
	int		words = 0;
	int 	i;
	int 	start = 0;
	int		finis = 0;
	
	while( fgets(line,80,fin) != NULL ){
		if( strlen(line) > 0 ){
			for( i = 0; i < strlen(line); i++ ){
				ch = line[i];
				if( tolower(ch) > 96 && tolower(ch) < 123 ){
					chars++;
					if( start == 0 ){
						start = 1;
						finis = 0;
					}
				}else{
					if( start == 1 && finis == 0 ){
						finis = 1;
						start = 0;
						words++;
					}
				}
			}
		}
	}
	
	fprintf(fout,"%d", (int)trunc(chars/words) );
	
	fclose(fin);
	fclose(fout);
	
	return 0;
}