Pagini recente » Cod sursa (job #899011) | Cod sursa (job #1122683) | Cod sursa (job #1710181) | Cod sursa (job #255709) | Cod sursa (job #807082)
Cod sursa(job #807082)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool is_letter(char c) {
c = (int)c;
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
}
int main () {
string word;
ifstream file_stream;
file_stream.open("text.in");
bool counted_extra = true;
int word_count = 0;
int total_length = 0;
int word_length;
int i, l;
while (file_stream >> word) {
word_length = 0;
for (i = 0, l = word.size(); i < l; ++i) {
bool il = is_letter(word[i]);
if (il) {
counted_extra = false;
++word_length;
}
if (il == false && i != l - 1 && counted_extra == false) {
++word_count;
counted_extra = true;
}
}
if (word_length) {
++word_count;
total_length += word_length;
}
}
file_stream.close();
ofstream output_file;
output_file.open("text.out");
output_file << total_length / word_count;
output_file.close();
}