Cod sursa(job #1059659)

Utilizator daniel.amarieiDaniel Amariei daniel.amariei Data 16 decembrie 2013 21:03:21
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <stdio.h>
#include <string.h>

char text[10000000];
int nr_cuvinte;
int lungime;

int isalpha(char c)
{
	if ((c >= 'A') && (c <= 'Z')) return 1;
	if ((c >= 'a') && (c <= 'z')) return 1;
	return 0;
}

int main()
{
	freopen("text.in", "r", stdin);
	freopen("text.out", "w", stdout);

	gets(text);
	int i = 0;
	while (text[i])
	{
		while (text[i] && !isalpha(text[i]))
		{
			++i;
		}

		while (text[i] && isalpha(text[i]))
		{
			++i;
			++lungime;
		}

		if (isalpha(text[i - 1]) && !isalpha(text[i]))
			++nr_cuvinte;
	}

	if (nr_cuvinte)
		printf("%d", lungime / nr_cuvinte);
	else
		printf("%d", 0);
	return 0;
}