Cod sursa(job #2663681)

Utilizator cristi_macoveiMacovei Cristian cristi_macovei Data 27 octombrie 2020 00:22:31
Problema Text Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>
#include <string>

bool is_alphabetic(char c) {
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

int main() {
  std::ifstream in("text.in");
  std::ofstream out("text.out");
  std::string str;

  in >> str;
  str += ' ';

  int len = 0, word_len = 0, words = 0;
  for (char c : str) {
    if (is_alphabetic(c))
      word_len++;
    else {
      if (word_len != 0)
        ++words;
      len += word_len;
      word_len = 0;
    }
  }

  out << (words == 0 ? 0 : len / words) << '\n';

  out.close();
  return 0;
}