Pagini recente » Cod sursa (job #612562) | Cod sursa (job #2664839) | Cod sursa (job #182982) | Cod sursa (job #1997877) | Cod sursa (job #2591624)
using namespace std;
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream f("text.in");
ofstream g("text.out");
//string lastword = new string();
//read file char by char
char c;
int totalWords =0;
int totalLen =0;
string lastWord = "";
while(f.get(c)) {
// cout<<c;
if (isalpha(c)){
lastWord+=c;
}
else {
int len = lastWord.length();
if (len!=0){ // avoid counting empty strings - happnes when more non ascii in a row
//end of word here. process the word and reset
//cout<<lastWord<<" "<<len<<" "<<endl;
totalWords++;
totalLen+= len;
lastWord.clear();
}
}
}
//cout<<totalLen<<" "<<totalWords<<endl;
g<<int (totalLen/totalWords);
}