Cod sursa(job #402968)

Utilizator Ph@ntomPopescu Darius Ph@ntom Data 24 februarie 2010 13:12:19
Problema Text Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 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)
    {
        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 + 1];
    
    in.read(buffer,length);
    in.close();
    length = 0;
    
    int k = NrCuvinte(buffer,length);
    out<<length / k;
    out.close();
    
    return 0;
}