Cod sursa(job #479648)

Utilizator ovydewParvu Ovidiu ovydew Data 24 august 2010 17:55:16
Problema Text Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
// Afla lungimea medie a cuvintelor din text

#include <fstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

const int MAXSIZE = 1024;

int main() {
	ifstream fin("text.in");
	ofstream fout("text.out");
	char* alfabet = new char[52];
	strcpy(alfabet,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
	char* buffer = new char[MAXSIZE];
	bool flag;
	int nr_w=0, nr_l=0;
	while (!fin.eof()) {
		flag = false;
		fin >> buffer;
		for(int i=0; i<(int)strlen(buffer); i++) {
			if (strchr(alfabet,buffer[i])==NULL) {
				flag = false;
			}
			else {
				if (flag==false) { 
					nr_w++;
					flag = true;
				}
				nr_l+=1;
			}
		}
	}
	if ((nr_l==0)||(nr_w==0))
		fout << 0;
	else
		fout << nr_l/nr_w;
	fin.close();
	fout.close();
	return 0;
}