Pagini recente » Cod sursa (job #1399403) | Cod sursa (job #2675790) | Cod sursa (job #2491616) | Cod sursa (job #138961) | Cod sursa (job #2276767)
#include <bits/stdc++.h>
using namespace std;
ifstream in("text.in");
ofstream out("text.out");
int main() {
ios::sync_with_stdio(false); in.tie(0); out.tie(0);
string line;
int nrChars = 0, nrWords = 0;
while(getline(in, line)) {
stringstream ss(line);
string word;
while(ss >> word) {
for(int i = 0; i < (int)word.size(); ++i) {
if(isalpha(word[i])) {
int j = i;
bool isWord = false;
while(j < (int)word.size() && isalpha(word[j])) {
isWord = true;
++nrChars;
++j;
}
if(isWord) {
nrWords++;
}
i = j - 1;
}
}
}
}
out << (nrChars / nrWords) << "\n";
in.close(); out.close();
return 0;
}