Cod sursa(job #390584)

Utilizator cristiprgPrigoana Cristian cristiprg Data 4 februarie 2010 00:22:01
Problema Text Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <cstdio>

bool litera(char c)
{
	if (c >= 'a' && c <='z')
		return 1;

	if (c >= 'A' && c <= 'Z')
		return 1;

	return 0;
}


int main()
{
	FILE *f = fopen("text.in", "r");
	char c;
	long Ltotal = 0, nr_cuv = 0, poz_init, i = 0;
	bool cuvant = false;
	while(fscanf(f, "%c", &c)!= EOF)
	{

		i++;
		if ((litera(c)) && cuvant == false)
		{
			cuvant = true;
			poz_init = i;
		}

		if (!(litera(c)) && cuvant == true)
		{
			Ltotal += i - poz_init;
			nr_cuv++;
			cuvant = false;
		}
	}

	fclose(f);
	f = fopen("text.out", "w");
	if (nr_cuv != 0)
		fprintf(f, "%ld", Ltotal / nr_cuv);
	else
		fprintf(f, "0\n");
	fclose(f);
	return 0;

}