Cod sursa(job #480481)

Utilizator budulaiSuman Dinu budulai Data 28 august 2010 01:58:22
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <stdlib.h>
//#include <ctype.h>
//#include <iostream>
//using namespace::std;
//using namespace std;
bool isalpha(char c)
{
	if(c<97) c+=32; //toupper
	return c>='a' && c<='z';
}
int main()
{
	char c;
	int word=0, total_words=0, sum=0;
	freopen("text.in", "r", stdin);
	freopen("text.out", "w", stdout);

	c=getchar();
	
	while(c!=EOF)
	{
		//printf("%c",c);
		if(isalpha(c)) word++;
		else if(word>0) { sum+=word; total_words++; word=0; }
		c=getchar();
	}
	if(word>0) { sum+=word; total_words++; word=0; }
	//printf("%d %d ",sum,total_words);
	printf("%d",sum/total_words);

	return 0;
}