Cod sursa(job #789253)

Utilizator vld7Campeanu Vlad vld7 Data 17 septembrie 2012 18:23:50
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>
#include <cstring>

using namespace std;

FILE *f = fopen ("text.in","r");
FILE *g = fopen ("text.out","w");

int n;
char text[1000005];

int main()
{
	int lgword, cnt, aux = 0;
	
	fgets (text, 1000005, f);
	n = strlen(text);
	
	lgword = cnt = 0;
	for (int i = 0; i < n; i++) {
		if ( (text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z') )
			lgword++, aux++;
		else {
			if (aux)
				cnt++;
			aux = 0;
		}
	}
	
	if (cnt)
		fprintf (g, "%d\n", lgword / cnt);
	else
		fprintf (g, "0\n");
	
	fclose(f);
	fclose(g);
	
	return 0;
}