Cod sursa(job #362397)

Utilizator digital_phreakMolache Andrei digital_phreak Data 9 noiembrie 2009 14:16:41
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
#include <string>

#define MAXN 1024*1024

using namespace std;

int NumWords,LenWords,Length;
char text[MAXN];

ifstream fin("text.in");
ofstream fout("text.out");

inline bool isAlpha(char c) {
	if ((c >= 'a') && (c <= 'z')) return true;
	if ((c >= 'A') && (c <= 'Z')) return true;
	return false;
}

int main() {
	Length = 0;
	while (!fin.eof()) {
		text[Length++] = fin.get();
	}
	
	int m = 0,l;
	while (m < Length) {
		l = 0;
		if (isAlpha(text[m])) NumWords++;
		while ((m < Length)&&(isAlpha(text[m]))) {
			l++;
			m++;
		}
		LenWords += l;
		m++;
	}

	fout << LenWords/NumWords << "\n";
	
	fin.close();
	fout.close();

}