Pagini recente » Cod sursa (job #712245) | Cod sursa (job #463769) | Cod sursa (job #2772263) | Cod sursa (job #2737521) | Cod sursa (job #1888116)
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream iFile("text.in");
freopen("text.out", "w", stdout);
string input;
while (true) {
string x;
iFile >> x;
input += x;
if (iFile.eof())
break;
input += " ";
}
int word_count = 0, word_len = 0, total_word_len = 0, i = 0;
bool not_word = true;
while (i ++ < input.size()) {
if (input[i] < 'A' || (input[i] > 'Z' && input[i] < 'a') || input[i] > 'z') {
if (!not_word) {
word_count ++;
total_word_len += word_len;
word_len = 0;
}
not_word = true;
} else {
not_word = false;
word_len ++;
if (i == input.size()) {
word_count ++;
total_word_len += word_len;
word_len = 0;
}
}
}
iFile.close();
printf("%d\n", total_word_len / word_count);
return 0;
}