Cod sursa(job #131570)

Utilizator mgntMarius B mgnt Data 4 februarie 2008 09:42:42
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cstdio>
using namespace std;

int const MAX = 1024 * 1024;
char text[4+MAX];

int
main () {
  FILE * io = fopen ("text.in", "r");
  setvbuf(io, NULL, _IOFBF, MAX);
  fgets(text, 1+MAX, io);
  fclose(io);
  int s=0, n=0, i=0, m = 0;
  while('\0' != text[i]) {
    while ( '\0' != text[i] && 
            !('a' <= text[i] && 'z' >= text[i]) && 
            !('A' <= text[i] && 'Z' >= text[i])    ) ++ i; // while
    
    while ( ('a' <= text[i] && 'z' >= text [i]) ||
            ('A' <= text[i] && 'Z' >= text [i])    ) { ++i; ++ m; }
    if (0 < m) {
      ++ n; s += m; m = 0;
    }
  }
  if (0 < n) m = s / n; else m = 0;
  io = fopen ("text.out", "w");
  fprintf (io, "%d\n", m);
  fclose (io);
  return 0;
}