Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大家看看咋是presentation Error呢?

Posted by 00448091 at 2005-04-16 20:28:11 on Problem 1405
#include <iostream.h>
#include <stdio.h>

const int N=4000;
class HugeInt
{
public:
	friend ostream& operator <<(ostream& ,HugeInt);
	HugeInt(long);
	HugeInt();
    HugeInt operator+(HugeInt&);
	HugeInt operator+(int);
	HugeInt operator*(HugeInt&);
private:
	__int64 integer[N];
	int size;
};
ostream &operator<<(ostream & output,HugeInt n)
{
	int i,j;
	for(i =0 ; i<N; i++)
	{
		if(n.integer[i]!=0)
			break;
	}
	if(i==N)
		output<<0;
	else
	{
		printf("%I64d",n.integer[i]);
		for(j=i+1 ; j<N ;j++)
		{
			for(int a=100000000;a>=1; a/=10)
			{
				if(n.integer[j]/a!=0)
					break;
				else
					printf("%d",0);
			}
			printf("%I64d",n.integer[j]);
		}
	}
		return output;
}
HugeInt::HugeInt()
{
	for(int i=0 ; i< N ; i++)
	{
		integer[i]=0;
	}
	size=0 ;
}

HugeInt::HugeInt(long val)
{
	for(int i=0 ; i<N ;i++)
	{
		integer[i]=0;
	}
	integer[N-1]=val;
	if(integer[N-1]==0)
		size=0;
	else
		size=1;
}
HugeInt HugeInt::operator +(int op2)
{
	HugeInt temp(op2);
	return temp+(*this);
}
HugeInt HugeInt::operator +(HugeInt& op2)
{
	HugeInt temp;
	int carry=0;

	for(int i = N-1 ; i>=0 ; i--)
	{
		temp.integer[i]=integer[i]+op2.integer[i]+carry;
		if(temp.integer[i]>=1000000000)
		{
			temp.integer[i]%=1000000000;
			carry=1;
		}
		else
			carry=0;
	}
	for(i=0 ;i<N ; i++)
	{
		if(temp.integer[i]!=0)
		{
			temp.size=N-i;
			break;
		}
	}
	return temp;
}
HugeInt HugeInt:: operator *(HugeInt& op2) 
{
	int j,k;
	HugeInt temp2;
	__int64 carry=0;
	int position=0;//record the position of digit in op2
	for(j=N-1 ; j >= N-op2.size ; j --)
	{
		HugeInt temp1;
		for(k=N-1 ;; k--)
		{
			temp1.integer[k-position]=integer[k]*op2.integer[j]+carry;
			carry=temp1.integer[k-position]/1000000000;
			temp1.integer[k-position]=temp1.integer[k-position]%1000000000;
		    if(carry==0 && k<=N-size)
				break;
		}
		temp2=temp2+temp1;
		position++;
	}
	
	for(j=0 ;j<N; j++)
	{
		if(temp2.integer[j]!=0)
		{
			temp2.size=N-j;
			break;
		}
	}
	return temp2;
}

int main(int argc, char* argv[])
{
	int num=0,i=0;
	cin>>num;
	HugeInt *out=new HugeInt[num];
	out[0]=1;
	for(i=1 ; i<num ; i++)
	{
		out[i]=out[i-1]*(out[i-1]+1);
	}
	for(i=0 ; i<num ; i++)
	{
		cout<<out[i]+1<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator