Cod sursa(job #701710)

Utilizator BugirosRobert Bugiros Data 1 martie 2012 17:24:04
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <cstdio>
using namespace std;

const int MAXTEXT = 1100000;

char c;
int nr_cuvinte,l_cuvinte;

void citire()
{
    freopen("text.in","r",stdin);
    freopen("text.out","w",stdout);
}

void prelucrare()
{
    bool cuvant = false;
    while (scanf("%c",&c) != EOF)
        if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
        {
            ++l_cuvinte;
            cuvant = true;
        }
        else if (cuvant)
        {
            ++nr_cuvinte;
            cuvant = false;
        }
    if (cuvant)
        ++nr_cuvinte;
}

int main()
{
    citire();
    prelucrare();
    printf ("%d",l_cuvinte / nr_cuvinte);
    return 0;
}

/*
#include <cstdio>
using namespace std;

const int MAXTEXT = 1100000;

char text[MAXTEXT];
int nr_cuvinte,l_cuvinte;

void citire()
{
    freopen("text.in","r",stdin);
    freopen("text.out","w",stdout);
    gets(text);
}

void prelucrare()
{
    bool cuvant = false;
    for (int i = 0;text[i] != 0;++i)
        if((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))
        {
            ++l_cuvinte;
            cuvant = true;
        }
        else if (cuvant)
        {
            ++nr_cuvinte;
            cuvant = false;
        }
    if (cuvant)
        ++nr_cuvinte;
}

int main()
{
    citire();
    prelucrare();
    printf ("%d",l_cuvinte / nr_cuvinte);
    return 0;
}
*/