Cod sursa(job #2309556)

Utilizator AlexPop28Pop Alex-Nicolae AlexPop28 Data 29 decembrie 2018 12:32:04
Problema Text Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 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");

const int NMAX = 1100000;

int n;
char s[NMAX];

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

  f.getline (s, NMAX);
  int n = strlen (s);
  int pos = 0;
  int num_words = 0;
  int total_len = 0;
  while (pos < n) {
    while (pos < n && !isAlpha (s[pos])) {
      ++pos;
    }

    if (pos == n) break;

    int len = 0;
    while (pos < n && isAlpha (s[pos])) {
      ++pos;
      ++len;
    }
    total_len += len;
    ++num_words;
  }

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

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