Cod sursa(job #1250361)

Utilizator foameteramonaFoamete Ramona foameteramona Data 28 octombrie 2014 00:35:20
Problema Text Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main(){
	std::string text;
	int count_cuv = 0, count_litere=0;

	std::ifstream input("text.in");
	getline(input, text);
	
	for (int i = 0; i < text.length(); i++){
		if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))
			count_litere++;
		if (text[i] == ' ')
		{
			if (i >= 1 && i <= text.length() - 1)
			{
				if ((text[i - 1] >= 'a' && text[i - 1] <= 'z') || (text[i - 1] >= 'A' && text[i - 1] <= 'Z'))
					count_cuv++;
				else
				{
					if (text[i - 1] == ',' || text[i - 1] == '\'' || text[i - 1] == '.' || text[i - 1] == '!' || text[i - 1] == '?')
						count_cuv++;
				}
			}
		}
		else
		{
			if (text[i] == '-')
			{
				if (i >= 1 && i <= text.length() - 1)
				{
					if (((text[i - 1] >= 'a' && text[i - 1] <= 'z') || (text[i - 1] >= 'A' && text[i - 1] <= 'Z')))
					{
						if (((text[i + 1] >= 'a' && text[i + 1] <= 'z') || (text[i + 1] >= 'A' && text[i + 1] <= 'Z')))
							count_cuv++;
					}
				}
			}
		}
	}
	count_cuv++;

	std::ofstream output("text.out");
	output<<count_litere/count_cuv;

	return 0;
}