Pagini recente » Monitorul de evaluare | Cod sursa (job #657953) | Diferente pentru home intre reviziile 590 si 591 | Cod sursa (job #713482) | Cod sursa (job #402968)
Cod sursa(job #402968)
#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;
}