Cod sursa(job #67530)

Utilizator ZweisteinAdrian VELICU Zweistein Data 25 iunie 2007 11:16:36
Problema Sarpe Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda Finala, Clasa a 9-a si gimnaziu Marime 1.09 kb
#include <stdio.h>
#include <memory.h>
#define MAXCIFS 1005
class Huge {
	public:
	char cif[MAXCIFS];
	int cifs;
	void operator+=(Huge h);
//	void set4(void);
	Huge(void);
	Huge(char *);
	Huge(int);
};
Huge::Huge(int x) {
	cifs=1;
	memset(cif,0,sizeof(cif));
	cif[1]=x;
};
Huge::Huge(void) {
	cifs=0;
	memset(cif,0,sizeof(cif));
};
Huge::Huge(char * fm) {
	cifs=strlen(fm); //???!?
	for (int i=1; i<=strlen(fm); i++) {
		cif[i]=fm[strlen(fm)-i]-'0';
	};
};
void Huge::operator+=(Huge h) {
	if (h.cifs>this->cifs) this->cifs=h.cifs;
	int t=0;
	for (int i=1; i<=this->cifs; i++) {
		this->cif[i]+=h.cif[i]+t;
		t=(this->cif[i]/10);
		this->cif[i]%=10;
	};
	if (t!=0) {
		this->cifs++;
		this->cif[this->cifs]=t;
	};
};
int main (void) {
	FILE * fi = fopen("sarpe.in","rt");
	FILE * fo = fopen("sarpe.out","wt");
	
	char nur[MAXCIFS];
	fscanf(fi,"%s",&nur);
	Huge nr(nur);
	Huge rez(nur);
	rez+=nr; rez+=nr; rez+=nr; // rez=4*n;
	if (!((nr.cifs==1) && (nr.cif[1]==2))) {
		Huge ajout(4);
		rez+=ajout;
	};
	for (int i=rez.cifs; i>0; i--) fprintf(fo,"%c",rez.cif[i]+'0');
	fprintf(fo,"\n");

	fclose(fi); fclose(fo);
};