Cod sursa(job #1670581)

Utilizator AdiNXAndrei Alexandru Moldovan AdiNX Data 31 martie 2016 21:00:01
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
// a - z    97 - 122
// A - Z    65 - 90

#include <iostream>
#include <fstream>
using namespace std;

bool isLetter(char c);

int main()
{
    int words = 0;
    int letters = 0;    
    bool inWord = false;
    
    ifstream fin("text.in");
    char c;
    while (fin >> noskipws >> c)
    {
        bool letter = isLetter(c);
        if (letter)
        {
            letters++;
            inWord = true;
        }
        else
        {
            if (inWord)
            {
                words++;
                inWord = false;
            }
        }
    }
    fin.close();
    
    if (isLetter(c) && inWord)
    {
        words++;
    }
    
    int answer = 0;
    if (words != 0)
    {
        answer = letters / words;
    }
    
    //cout << "Answer: " << answer << endl;    
    //cout << endl << "Done!" << endl << "Press any key to continue..." << endl;
    //cin.ignore();
    
    ofstream fout("text.out");
    fout << answer;
    fout.close();
    
    return 0;
}

bool isLetter(char c)
{
    return ((c >= 65 && c <= 90) || (c >= 97 && c <= 122));
}