Cod sursa(job #385378)

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

/*
 *
 */
using namespace std;
int main()
{
    char* s;
    unsigned int size, nr=0, length=0, i, j;
    FILE *fin=fopen( "text.in", "rt" );
    fseek( fin, 0, SEEK_END ); //go to the end
    size=ftell( fin ); //get the size of the file
    size=sizeof(char)*size;
    s=new 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( i=0; i < size; ++i )
    {
        if( ( s[i] >= 'a' && s[i] <= 'z' ) || ( s[i] >= 'A' && s[i] <= 'Z' ) )
        {++nr;
            for( j=i+1; j < size && ( ( s[j] >= 'a' && s[j] <= 'z' ) || ( s[j] >= 'A' && s[j] <= 'Z' ) ); ++j );
             length+=j-i;
             i=j-1;
        }
    }
    fprintf( fopen("text.out", "wt" ), "%u", length/nr );
    return 0;
}