Cod sursa(job #479652)

Utilizator ovydewParvu Ovidiu ovydew Data 24 august 2010 18:24:19
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
// Afla lungimea medie a cuvintelor din text

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

using namespace std;

const int MAXSIZE = 1024;

int main() {
	FILE* fin = fopen("text.in","r");
	ofstream fout("text.out");
	char* alfabet = new char[52];
	strcpy(alfabet,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
	char buffer;
	bool flag;
	int nr_w=0, nr_l=0;
	while (fscanf(fin,"%c",&buffer)!=EOF) {
		if (strchr(alfabet,buffer)==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 << (int)nr_l/nr_w;
	fout.close();
	return 0;
}