Cod sursa(job #1852314)

Utilizator mouse_wirelessMouse Wireless mouse_wireless Data 20 ianuarie 2017 18:07:34
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

#ifdef INFOARENA
#define ProblemName "fractal"
#endif

#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "fis.in"
#define OuFile "fis.out"
#endif
typedef long long LL;

int tlen, tnum;

void update(char *b) {
	int clen = 0;
	for(;;++b) {
		char c = *b;
		if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
			++clen;
		else {
			if (clen) {
				tlen += clen;
				++tnum;
				clen = 0;
			}
			if (!c) break;
		}
	}
}

const int BUFSZ = 8192 * 1024;
char buf[BUFSZ];

int parse() {
	tlen = tnum = 0;
	while (1) {
		int rez = fread(buf, 1, BUFSZ, stdin);
		if (rez <= 0) break;
		buf[rez] = 0;
		update(buf);
	}
	return tlen / tnum;
}

int main() {
	freopen(InFile, "r", stdin);
	freopen(OuFile, "w", stdout);
	printf("%d\n", parse());
	return 0;
}