Cod sursa(job #630107)

Utilizator silviuboganSilviu Bogan silviubogan Data 4 noiembrie 2011 18:54:04
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cstdio>
using namespace std;

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

	char c;
	int lengthOfCurrentWord = 0,
		wordCount = 0,
		totalLengthOfWordsInText = 0;
	bool inWord = false;

	while (scanf("%c", &c) != EOF) {
		if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
			if (!inWord) {
				inWord = true;
				lengthOfCurrentWord = 1;
			} else {
				lengthOfCurrentWord++;
			}
		} else if (inWord) {
			totalLengthOfWordsInText += lengthOfCurrentWord;
			wordCount++;
			inWord = false;
		}
	}
	if (inWord) {
		totalLengthOfWordsInText += lengthOfCurrentWord;
		wordCount++;
	}

	printf("%d", totalLengthOfWordsInText / wordCount);

	return 0;
}