Cod sursa(job #348914)

Utilizator TFifesPorcescu Alexandru TFifes Data 17 septembrie 2009 16:47:42
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
int main ()
{
    ifstream x("text.in",ios::ate);
ofstream y("text.out");
   unsigned short n,nr=0,cv=0;
   n=x.tellg();
   x.seekg(0,ios::beg);
   char *p,*q,sep[]=" .,/!?@#$%^^&&&**()-_1234567890$%^&(){}"";";
   p=new (nothrow) char [n+2];
   if(!p)
   {
       cout<<"Dynamic memory couldn't be allocated";
       return -1;
   }
   x.getline(p,n+1);
   x.close();
   q=strtok(p,sep);
   while(q)
   {
       nr+=strlen(q);
       cv++;
       q=strtok(NULL,sep);
   }

   if(cv!=0)
   {
   y<<nr/cv;
   }
   y.close();

   return 0;
}