Cod sursa(job #2666224)

Utilizator cristi_macoveiMacovei Cristian cristi_macovei Data 1 noiembrie 2020 11:11:50
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <iostream>
#include <fstream>
#include <ios>

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");

  char c, prev;
  int len, words;

  in >> prev;
  len = words = is_alphabetic(prev);

  while (in >> std::noskipws >> c) {
    if (is_alphabetic(c)) {
      ++ len;

      if (!is_alphabetic(prev))
        ++ words;
    }

    prev = c;
  }

  out << len / words << '\n';

  out.close();
  return 0;
}