Cod sursa(job #1312168)

Utilizator Tzappy90Mihalache Constantin Tzappy90 Data 8 ianuarie 2015 22:52:28
Problema Text Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int isletter(char a)
{
	if( ('a'<=a && a<='z') || ('A'<=a && a<='Z'))
		return 1;
	return 0;
}
int main()
{
	long int letter=0,word=0,i;
	int start;
	FILE *in = fopen("text.in","r");
	FILE *out = freopen("text.out","w",stdout);
	char *text = (char*)malloc(1000000*sizeof(char));
	char *p;
	fgets(text,1000000,in);
	text[strlen(text)-1] = '\0';
	fclose(in);
	start = 0;
	for(i=0;i<strlen(text);i++)
	{
		if(isletter(text[i]))
		{
			letter++;
			if(!start)
			{
				word++;
			}
			start = 1;
		}
		else
			start = 0;
	}
	if(word)
		printf("%ld\n",letter/word);
	else
		printf("%d\n",0);

	return 0;
}