Cod sursa(job #1448453)

Utilizator andreipnAndrei Petre andreipn Data 7 iunie 2015 03:27:47
Problema Text Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>
#include <string.h>

#define MAX(a,b)	((a) < (b) ? (b) : (a))
#define IS_LETTER(c)	((c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A'))

int main() {
	FILE *in = fopen("text.in", "r"),
	     *out = fopen("text.out", "w");
	char c, last_c = ' ';
	int words = 0;
	int total_len = 0;

	while ((c = (char) fgetc(in)) != EOF) {
		if (IS_LETTER(c)) {
			total_len++;
			if (!IS_LETTER(last_c))
				words++;
		}
		last_c = c;
	}
	printf("words %d, total %d\n", words, total_len);

	fprintf(out, "%d", total_len / MAX(1, words));

	fclose(in);
	fclose(out);
	return 0;
}