Cod sursa(job #3177028)

Utilizator VladNANegoita Vlad-Andrei VladNA Data 28 noiembrie 2023 12:16:49
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
#include <cctype>
#include <iterator>
#include <numeric>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,avx,fma,avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

void solve() {
  vector<string> collector;
  string aux;
  while (cin >> aux)
    collector.push_back(aux);

  vector<string> words;
  auto parse_words = [&words](string &str) {
    string curr;
    for (char c : str) {
      if (isalpha(c)) {
        curr.push_back(c);
      } else {
        if (!curr.empty())
          words.push_back(curr);
        curr.clear();
      }
    }

    if (!curr.empty()) {
      words.push_back(curr);
    }
  };

  for (string &w : collector)
    parse_words(w);

  int length =
      accumulate(words.begin(), words.end(), 0,
                 [](int acc, string &w) -> int { return acc + w.size(); });
  cout << length / words.size() << endl;
}

int main() {
  freopen("text.in", "r", stdin);
  freopen("text.out", "w", stdout);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();

  return 0;
}