Cod sursa(job #762392)

Utilizator Marius_mFMI-M2 Marius Melemciuc Marius_m Data 30 iunie 2012 02:12:31
Problema Text Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<iostream>
#include<cstdio>

using namespace std;

class A
{
	char* s;
	int n;
	FILE *in,*out;
public:
	A();
	~A();
	void Read();
	int NrLitere();
	int NrCuvinte();
	void Rez();
};

A::A()
{
	in = fopen("text.in","r");
	out = fopen("text.out","w");
	s = new char[1000000];
}

A::~A()
{
	delete [] s;
	fclose(in);
	fclose(out);
}

void A::Read()
{
	fgets(s,1000000,in);//fscanf(in,"%s",s);
}

int A::NrLitere()
{
	int nr = 0;
	for( int i = 0 ; s[i] != NULL ; i++ )
		if( (s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') )
			nr++;
	return nr;
}

int A::NrCuvinte()
{
	int nr = 0,k;
	for( int i = 0 ; s[i] != NULL ; i++ )
	{
		k = 0;
		while( (s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z' ))
		{
			i++;
			k = 1;
		}
		if( k == 1 )
			nr++;
	}
	return nr;
}

void A::Rez()
{
	fprintf(out,"%d",NrLitere()/NrCuvinte());
}

int main()
{
	A a;
	a.Read();
	a.Rez();
	return 0;
}