Cod sursa(job #402976)

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

int NrCuvinte(char *s,int &lung)
{
    char *t = new char[strlen(s)];
    strcpy(t,s);
    char *p = strtok(t," [ ],.-");
    int cnt = 0;
    while(p != NULL)
    {
        if(strcmp(p,",") && strcmp(p,"-"))
        {
            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];
    
    in.read(buffer,length);
    in.close();
    length = 0;
    
    int k = NrCuvinte(buffer,length);
    out<<int(length / k);
    out.close();
    
    return 0;
}