Cod sursa(job #547502)

Utilizator truenighttruenight truenight Data 6 martie 2011 13:44:41
Problema Text Scor 20
Compilator c Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>
#include <ctype.h>

#define IN "text.in"
#define OUT "text.out"
#define N 50000000

char text[N];
long read(void);

int main(void) {

	long len_text = 0, nr_cuv = 0, i;

	freopen(IN, "r", stdin);
	freopen(OUT, "w", stdout);

	read();

	for(i = 0; text[i] != '\0'; ++i) if(isalpha(text[i])) ++len_text;
	for(i = 1; text[i] != '\0'; ++i) 
		if(isalpha(text[i - 1]) && !isalpha(text[i])) ++nr_cuv;

	printf("%ld", len_text / nr_cuv);

	return 0;
}

long read(void) {

	char ch;
	long i = 0;

	while((ch = getchar()) != '\n') text[i++] = ch;
	text[i] = '\0';

	return i;
}