Cod sursa(job #609615)

Utilizator coleguFatu Vlad Cristian colegu Data 22 august 2011 14:22:37
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
    
	ifstream f;
	ofstream g;
	int nrLetters, nrWords;
	string str;
	nrLetters = 0;
	nrWords = 0;
	f.open("text.in");
	g.open("text.out");
	getline(f, str);
	if (str.size() != 0)
	{
		for (int i=0; i<str.size();i++)
		{
			if (isalpha(str[i])) nrLetters++;
			else if (isalpha(str[i-1])) nrWords++;
		} 
		if (isalpha(str[str.size()-1])) nrWords++;
		if (nrWords != 0)
			g << nrLetters/nrWords;
		else g<<"0";
	}
	else g <<"0";
	return 0;
}