Pagini recente » Cod sursa (job #685113) | Cod sursa (job #556406) | Cod sursa (job #2943859) | Cod sursa (job #2506993) | Cod sursa (job #807084)
Cod sursa(job #807084)
#include <iostream>
#include <fstream>
#include <cstdio>
using namespace std;
bool is_letter(char c) {
c = (int)c;
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
}
int main () {
char letter;
FILE *input_file;
input_file = fopen("text.in", "r");
bool counted_extra = true;
int word_count = 0;
int total_length = 0;
int word_length;
int i, l;
while (!feof(input_file)) {
fscanf(input_file, "%c", &letter);
if (is_letter(letter)) {
++word_length;
} else {
if (word_length) {
++word_count;
total_length += word_length;
}
word_length = 0;
}
}
fclose(input_file);
ofstream output_file;
output_file.open("text.out");
if (word_count == 0) {
output_file << 0;
} else {
output_file << total_length / word_count;
}
output_file.close();
}