Cod sursa(job #1871867)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 7 februarie 2017 18:26:50
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb

#include <fstream>
#include <string>

std::ifstream fin("text.in");
std::ofstream fout("text.out");

std::string input;

char letters[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };



int main()
{
	unsigned long long numberOfChars = 0;
	unsigned long long numberOfWords = 0;


	while (getline(fin, input))
	{
		bool waspreviousLetter = false;
		bool found = false;
		for (int i = 0; i<input.size(); i++)
		{
			found = false;
			for (auto y : letters)
			{
				if (input[i] == y || input[i] == (y - 32))
				{
					found = true;
					if (waspreviousLetter == false)
					{
						numberOfWords++;
					}
					waspreviousLetter = true;
					numberOfChars++;
					break;
				}
			}
			if (found == false)
			{
				waspreviousLetter = false;
			}
		}
	}

	fout << numberOfChars / numberOfWords;
	return 0;
}