#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MAX = 110;
class CHugeInt
{
private:
int inum;
char* cnum;
public:
CHugeInt(char *num2,int num1=-1):cnum(num2),inum(num1){}
CHugeInt(int num1,char* num2=NULL):inum(num1),cnum(num2){}
CHugeInt(const CHugeInt &xxx)
{
inum=xxx.inum;
cnum = new char[strlen(xxx.cnum) + 1];
strcpy(cnum,xxx.cnum);
}
/*
~CHugeInt() {
if (cnum)
delete []cnum;
};
*/
friend ostream& operator<<( ostream&o,const CHugeInt& xx);
friend CHugeInt operator+(const CHugeInt& temp,int b);
friend CHugeInt operator+(int b,const CHugeInt& temp);
CHugeInt operator+(const CHugeInt& temp,int b)
{
CHugeInt a=temp;
if(a.cnum==NULL)
{
a.inum=b+a.inum;
return a;
}
else
{
int i=0;
int len1=strlen(a.cnum);
char* cnum1=new char[len1+1];
strrev(a.cnum);
for(i=0;i<MAX;i++)
{
if(b!=0)
{
*(cnum1+i)=b%10+'0';
b=b/10;
}
if(b==0)
{
*(cnum1+i)='0';
}
}
for(i=0;i<len1;i++)
{
*(a.cnum+i+1)=(*(a.cnum+i)-'0'+*(cnum1+i)-'0')/10+'0';
*(a.cnum+i)=(*(a.cnum+i)-'0'+*(cnum1+i)-'0')%10+'0';
}
*(a.cnum+len1+1)=0;
strrev(a.cnum);
delete []cnum1;
}
return a;
}
void main()
{
CHugeInt a("1234545436342424354354365289899834234235");
CHugeInt d(9999);
CHugeInt t1 = CHugeInt("100000088888888");
CHugeInt temp = t1 + 111112; //这一行就有问题了
}
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MAX = 110;
class CHugeInt
{
private:
int inum;
char* cnum;
public:
CHugeInt(char *num2,int num1=-1):cnum(num2),inum(num1) {}
CHugeInt(int num1,char* num2=NULL):inum(num1),cnum(num2) {}
CHugeInt(const CHugeInt &xxx)
{
inum=xxx.inum;
cnum = new char[strlen(xxx.cnum) + 1];
strcpy(cnum,xxx.cnum);
}
~CHugeInt() {
if (cnum)
delete []cnum;
}
friend ostream& operator<<( ostream&o,const CHugeInt& xx);
friend CHugeInt operator+(const CHugeInt& temp,int b);
friend CHugeInt operator+(int b,const CHugeInt& temp);
};
CHugeInt operator+(const CHugeInt& temp,int b)
{
CHugeInt a=temp;
if(a.cnum==NULL)
{
a.inum=b+a.inum;
return a;
}
else
{
int i=0;
int len1=strlen(a.cnum);
char* cnum1=new char[len1+1];
strrev(a.cnum);
for(i=0; i<MAX; i++)
{
if(b!=0)
{
*(cnum1+i)=b%10+'0';
b=b/10;
}
if(b==0)
{
*(cnum1+i)='0';
}
}
for(i=0; i<len1; i++)
{
*(a.cnum+i+1)=(*(a.cnum+i)-'0'+*(cnum1+i)-'0')/10+'0';
*(a.cnum+i)=(*(a.cnum+i)-'0'+*(cnum1+i)-'0')%10+'0';
}
*(a.cnum+len1+1)=0;
strrev(a.cnum);
delete []cnum1;
}
return a;
}
int main()
{
CHugeInt a("1234545436342424354354365289899834234235");
CHugeInt d(9999);
CHugeInt t1 = CHugeInt("100000088888888");
CHugeInt temp = t1 + 111112; //这一行就有问题了
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。