Cod sursa(job #967030)

Utilizator toranagahVlad Badelita toranagah Data 26 iunie 2013 22:32:37
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <cctype>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

ifstream fin("text.in");
ofstream fout("text.out");

string text;

int main() {
  getline(fin, text);
  
  unsigned int words_length = 0;
  unsigned int num_words = 0;
  for (unsigned int i = 0; i < text.size(); ++i) {
    if (isalpha(text[i])) {
      while (i < text.size() && isalpha(text[i])) {
        ++words_length;
        ++i;
      }
      ++num_words;
    }
  }
  
  fout << words_length / num_words;
  return 0;
}