Cod sursa(job #1524832)

Utilizator AndreiIstetulAndrei Andrei AndreiIstetul Data 14 noiembrie 2015 14:40:54
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <string>
#include <sstream>
#include <cctype>

typedef unsigned uint;

std::fstream in, out;
std::string text;
uint words, len, llen;
bool word;

inline void getWholeFile()
{
	std::stringstream ss;
	ss << in.rdbuf();
	text = ss.str();
}

int main(int argv, char **argc)
{
	in.open("text.in", std::fstream::in);
	out.open("text.out", std::fstream::out);

	getWholeFile();

	llen = text.size();
	for (uint i = 0; i < llen; ++i)
		if (std::isalpha(text[i]))
		{
			++len;
			word = true;
		}
		else if (word)
		{
			++words;
			word = false;
		}

	out << len / words;
	return 0;
}