Cod sursa(job #2309558)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 29 decembrie 2018 12:38:23
Problema Text Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;

ifstream f ("text.in");
ofstream g ("text.out");

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen (".in", "r", stdin);
#endif

  char c;
  int pos = 0;
  int num_words = 0;
  int total_len = 0;
  f >> noskipws;
  while (!f.eof()) {
    f >> c;
    if (!isAlpha (c)) {
      continue;
    }

    if (f.eof()) break;

    int len = 0;
    while (!f.eof() && isAlpha (c)) {
      ++len;
      f >> c;
    }
    total_len += len;
    ++num_words;
  }

  g << total_len / num_words << '\n';

  f.close();
  g.close();
  return 0;
}