Cod sursa(job #2140406)

Utilizator Laurentiu_cDobrescu Laurentiu Laurentiu_c Data 23 februarie 2018 14:24:07
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>


using namespace std;

ifstream in("intrare.txt");
ofstream out("iesire.txt");

int CountWords(std::string strString)
{
	int nSpaces = 0;
	unsigned int i = 0;

	// Skip over spaces at the beginning of the word
	while (isspace(strString.at(i)))
		i++;

	for (; i < strString.length(); i++)
	{
		if (isspace(strString.at(i)))
		{
			nSpaces++;

			// Skip over duplicate spaces & if a NULL character is found, we're at the end of the string
			while (isspace(strString.at(i++)))
				if (strString.at(i) == '\0')
					nSpaces--;
		}
	}

	// The number of words = the number of spaces + 1
	return nSpaces + 1;
}

int countLetter(std::string text)
{
	int nLetter=0;
	for (int i = 0; i < text.length(); i++)
	{
		if (isalpha(text.at(i)))
			nLetter++;
	}



	return nLetter;
}

int main()
{
	
	string buffer;
	int numberWords;
	getline(in, buffer);
	numberWords = CountWords(buffer);
	int numberOfLetter = countLetter(buffer);
	//cout << numberWords << " " << numberOfLetter << endl;
	out << (int)(numberOfLetter/ numberWords);





	system("pause");
	return 0;
}