Cod sursa(job #733536)

Utilizator alex_unixPetenchea Alexandru alex_unix Data 12 aprilie 2012 14:01:31
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstdio>

char buffer [1024 * 1024];

int main (void)
{
    int in_file(open("text.in",O_RDONLY));
    int read_size(read(in_file,buffer,sizeof(buffer)));
    close(in_file);
    char *ptr(buffer),*limit(buffer + read_size);
    unsigned int cuvinte(0), litere(0), cuv;
    do
    {
        if (*ptr >= 'a' && *ptr <= 'z' || *ptr >= 'A' && *ptr <= 'Z')
        {
            cuv = 1;
            ++ptr;
            while (ptr < limit && *ptr >= 'a' && *ptr <= 'z' || *ptr >= 'A' && *ptr <= 'Z')
            {
                ++ptr;
                ++cuv;
            }
            ++cuvinte;
            litere += cuv;
        }
        ++ptr;
    }
    while (ptr < limit);
    std::freopen("text.out","w",stdout);
    printf("%u\n",litere / cuvinte);
    std::fclose(stdout);
    return 0;
}