Cod sursa(job #1723115)

Utilizator antanaAntonia Boca antana Data 29 iunie 2016 18:27:38
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <cstdio>
#define BUF_SIZE 4096
using namespace std;
char buf[BUF_SIZE], c;
int pos=BUF_SIZE, nrcuv, lung;
inline char getChar(FILE *f)
{
    if(pos==BUF_SIZE) fread(buf, 1, BUF_SIZE, f), pos=0;
    return buf[pos++];
}
inline void nextcuv(FILE *f)
{
    while(!((c>='a' && c<='z') || (c>='A' && c<='Z')) && c!=0)
        c=getChar(f);
}
int main()
{
    FILE *fin, *fout;
    fin=fopen("text.in", "r");
    fout=fopen("text.out", "w");
    c=getChar(fin);
    while(c)
    {
        nextcuv(fin);
        if((c>='a' && c<='z') || (c>='A' && c<='Z')){
            nrcuv++;
            while((c>='a' && c<='z') || (c>='A' && c<='Z')) lung++, c=getChar(fin);
        }
    }
    fprintf(fout, "%d", lung/nrcuv);
    fclose(fin);
    fclose(fout);
    return 0;
}