Cod sursa(job #479653)

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

#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int main() {
	FILE* fin = fopen("text.in","r");
	FILE* fout = fopen("text.out","w");
	char* alfabet = new char[52];
	strcpy(alfabet,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
	char buffer;
	bool flag = false;
	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;
		}
	}
	fprintf(fout, "%d", nr_l/nr_w);
	return 0;
}