Pagini recente » Cod sursa (job #648582) | Cod sursa (job #3215472) | Cod sursa (job #768357) | Cod sursa (job #2894704) | Cod sursa (job #2663680)
#include <iostream>
#include <fstream>
#include <string>
bool is_alphabetic(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
int main() {
std::ifstream in("text.in");
std::ofstream out("text.out");
std::string str;
std::getline(in, str);
str += ' ';
int len = 0, word_len = 0, words = 0;
for (char c : str) {
if (is_alphabetic(c))
word_len++;
else {
if (word_len != 0)
++words;
len += word_len;
word_len = 0;
}
}
out << (words == 0 ? 0 : len / words) << '\n';
out.close();
return 0;
}