Cod sursa(job #2957188)

Utilizator nicu_ducalNicu Ducal nicu_ducal Data 21 decembrie 2022 21:56:04
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <bits/stdc++.h>
using namespace std;

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;

const int INF = INT_MAX, MOD = 1e9 + 7;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  /// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  ifstream cin("text.in");
  ofstream cout("text.out");

  i64 ans = 0, words = 0, now_len;
  char c;
  bool word = false;

  while (cin.get(c)) {
    if (not isalpha(c) and not word)
      continue;
    else if (not isalpha(c) and word) {
      ++words;
      ans += now_len;
      word = false;
    } else if (isalpha(c) and not word) {
      word = true;
      now_len = 1;
    } else
      ++now_len;
  }

  if (word) {
    ++words;
    ans += now_len;
  }

  cout << ans / words << "\n";

  return 0;
}