Cod sursa(job #402969)

Utilizator Ph@ntomPopescu Darius Ph@ntom Data 24 februarie 2010 13:14:21
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int NrCuvinte(char *s,int &lung)
{
    char *t = new char[strlen(s) + 1];
    strcpy(t,s);
    char *p = strtok(t," ");
    int cnt = 0;
    while(p != NULL)
    {
        cnt++;
        while(*p != '\0')
        {    
            if((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z'))
                lung++;
            p = p + 1;
        }
        p = strtok(NULL," ");
    }
    return cnt;
}

int main()
{
    fstream in,out;
    char *buffer;
    
    in.open("text.in",ios::in);
    out.open("text.out",ios::out);
    
    in.seekg(0,ios::end);
    int length = in.tellg();
    in.seekg(0,ios::beg);
    buffer = new char[length + 1];
    
    in.get(buffer,length);
    in.close();
    length = 0;
    
    int k = NrCuvinte(buffer,length);
    out<<length / k;
    out.close();
    
    return 0;
}