Pagini recente » Cod sursa (job #891462) | Cod sursa (job #917407) | Cod sursa (job #2112572) | Cod sursa (job #3231694) | Cod sursa (job #2761952)
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
ifstream fin("text.in");
ofstream fout("text.out");
bool isLetter(char c){
int asciiCode = (int)(c);
return (asciiCode > 64 && asciiCode < 91) || (asciiCode > 96 && asciiCode < 123 );
}
int main(){
string text;
long long nrLetters = 0, nrWords = 1;
int averageLength;
getline(fin,text);
for(int i = 0; i<text.length(); ++i){
if(isLetter(text[i])){
++nrLetters;
}
if((text[i] == ' ' || text[i] == '-') && isLetter(text[i-1])){
++nrWords;
}
}
cout<<nrLetters<< '\n';
cout<<nrWords<<'\n';
averageLength = nrLetters/nrWords;
fout<<averageLength;
return 0;
}