Cod sursa(job #2663642)

Utilizator cristi_macoveiMacovei Cristian cristi_macovei Data 26 octombrie 2020 22:36:52
Problema Text Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 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;

  std::getline(in, str);

  int words = 0, len = is_alphabetic(str[0]);
  for (int i = 1; i < (int)str.size(); ++i) {
    if (is_alphabetic(str[i]))
      ++len;
    else if (is_alphabetic(str[i - 1]))
      ++words;
  }
  if (is_alphabetic(str.back()))
    ++words;

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

  out.close();
  return 0;
}