Cod sursa(job #972725)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 12 iulie 2013 15:56:45
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("text.in");
ofstream g("text.out");
int letters,words;
string Str;
bool is_letter(char ch)
{
    return (ch<='Z' && ch>='A') || (ch<='z' && ch>='a');
}

void Solve()
{
    int i=0;
    bool was_letter=0;
    while(Str[i]!=0)
    {
        if(is_letter(Str[i])==1 && was_letter==0)
        {
            words++;
            letters++;
            was_letter=1;
            i++;
            continue;
        }
        if(is_letter(Str[i])==1)
        {
            letters++;
            was_letter=1;
            i++;
            continue;
        }
        if(is_letter(Str[i])==0)
            was_letter=0;
        i++;
    }
}
void Read_and_Process()
{
    int x=1;
    while(!f.eof())
    {
        getline(f,Str);
        Solve();
    }
}
void Print()
{
    if(words!=0)
        g<<letters/words<<"\n";
    else
        g<<0<<"\n";
}
int main()
{
    Read_and_Process();
    Print();
    return 0;
}