Cod sursa(job #1339648)

Utilizator atty97Toth Attila atty97 Data 11 februarie 2015 00:58:27
Problema Text Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
#include <string>
using namespace std;

int main()
{
    ifstream in_f("text.in");
    ofstream out_f("text.out");
    string text = "";

    while (!in_f.eof())
    {
        getline(in_f, text);
    }

    int size = text.length();
    unsigned short letters = 0, words = 0, avg = 0;

    for (unsigned i = 0; i < size; i++)
    {
        if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))
        {
            if ((text[i - 1] == ' ') || (text[i - 1] == '-'))
            {
                ++words;
            }
            ++letters;
        }
    }

	avg = letters / words;
	out_f << avg;


	return 0;
}