Pagini recente » Cod sursa (job #2251241) | Cod sursa (job #2637332) | Cod sursa (job #1989114) | Cod sursa (job #756212) | Cod sursa (job #630107)
Cod sursa(job #630107)
#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;
}