Cod sursa(job #1550508)
| Utilizator | Data | 13 decembrie 2015 20:05:39 | |
|---|---|---|---|
| Problema | Text | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <fstream>
#include <string>
inline bool isAlpha(char c)
{
return ('a'<=c&&c<='z') ||('A'<=c&&c<='Z');
}
int main()
{
std::ifstream in("text.in");
std::ofstream out("text.out");
std::string text;
std::getline(in, text);
long n_alphas = 0, n_words = 0;
bool prev_alpha = false;
for(auto c : text) {
if(isAlpha(c)) {
if(!prev_alpha) ++n_words;
prev_alpha = true;
++n_alphas;
}
else {
prev_alpha = false;
}
}
out<<n_alphas/n_words<<'\n';
return 0;
}
