Cod sursa(job #1210724)

Utilizator Kerriganamihut Kerrigan Data 20 iulie 2014 22:27:11
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
/*******************************************************************************************
*           .--.																		   *
* ::\`--._,'.::.`._.--'/::			@author Ana M. Mihut	@course InfoArena Tryout	   *
* ::::. `  __::__ ' .:::::			@alias  LT-Kerrigan		@date   19.07.2014			   *
* ::::::-:.`'..`'.:-::::::			@link   http://infoarena.ro/problema/text		       *
* ::::::::\ `--' /::::::::			@detail "Use regex" they said "It'll be fun" they said *
*																						   *
********************************************************************************************/
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>

using namespace std;

FILE *in = fopen("text.in", "r");
FILE *out = fopen("text.out", "w");
char c;

bool IsLetter(char c) { return (c >= 65 && c <= 90) || (c >= 97 && c <= 122); }

void AvgLen() {
	int i = 0, countLetter = 0, countWords = 0;
	while (fscanf(in, "%c", &c) != EOF){
		if (IsLetter(c)){
			countLetter++;
			if (i == 0) countWords++;
			i = 1;
		}
		else i = 0;
	}
	fprintf(out, "%d\n", countLetter / countWords);
}

int main(){
	AvgLen();
	return 0;
}