Cod sursa(job #385369)

Utilizator alexandru92alexandru alexandru92 Data 22 ianuarie 2010 17:46:47
Problema Text Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
/* 
 * File:   main.cpp
 * Author: virtualdemon
 *
 * Created on January 22, 2010, 5:31 PM
 */
#include <cstdio>

/*
 *
 */
using namespace std;
int main()
{
    char* s, *p, *q;
    unsigned int size, nr=0, length=0;
    FILE *fin=fopen( "text.in", "rt" );
    fseek( fin, 0, SEEK_END ); //go to the end
    size=ftell( fin ); //get the size of the file
    s=new char[ sizeof(char)*size+1 ]; //allocate memory
    rewind( fin ); //go back to the beginning
    fread( s, sizeof(char), size, fin ); //copy the data from the buffer to s
    for( p=s; *p; )
    {
        if( ( *p >= 'a' && *p <= 'z' ) || ( *p >= 'A' && *p <= 'Z' ) )
        {++nr;
            for( q=p ; *p && ( ( *p >= 'a' && *p <= 'z' ) || ( *p >= 'A' && *p <= 'Z' ) ); ++p );
            length+=p-q;
        }
        else ++p;
    }
    fprintf( fopen("text.out", "wt" ), "%u", length/nr );
    return 0;
}