巨型整數運算符重載實現部分

巨型整型運算重載--實現部分(.cpp)

關鍵詞HugeInt    運算符重載   

#define MAXLEN 1000//定義巨型數據的最大長度
#include < conio.h >
//*----------------------------各構造函數的實現[begin]---------------------------*//

//------------------HugeInt類構造函數(不帶參數 使用默認值0初始化)---------------//
/*
函數名:HugeInt類構造函數
傳入參數:字符指針
功能:實現使用默認值0初始化類對象
*/
HugeInt::HugeInt()
{
//初始化一帶頭結點的空雙向循環鏈表//
RightEnd=0;
node *temp=new node;
temp->left=temp;
temp->right=temp;
head=temp;
head->data=0;
RightEnd=head;
n=0;
}

//------------------HugeInt類構造函數(參數類型 字符串)----------------------------//
/*
函數名:HugeInt類構造函數
傳入參數:字符指針
功能:實現使用字符串初始化類對象
*/
HugeInt::HugeInt(char *data)
{
//初始化一帶頭結點的空雙向循環鏈表//
RightEnd=0;
node *temp=new node;
temp->left=temp;
temp->right=temp;
head=temp;
head->data=0;
RightEnd=head;
n=0;

//接收傳入的參數
char *tempdata=new char[strlen(data)+1];
strcpy(tempdata,data);

//如果輸入的數據串合法 則將其分段並存儲在鏈表中//
//說明:比如字符串"000100000632000"插入到鏈表中各結點爲0,1000,63,2000//
if(IsRight(data))
{ //根據符號設置頭結點值 負數爲1 正數爲0//
if(data[0]=='-')
{head->data=1;}
else
{head->data=0;}

//取輸入數據串的絕對值
char *newdata=new char[strlen(tempdata)+1];
strncpy(newdata,abs(tempdata),strlen(newdata));

short int len=strlen(newdata);//len 數據串的位數 不包括符號

//當數據的位數大於分段的單位4時 以4位一組作爲結點循環插入到鏈表//
while(len>=4)
{
char temp[5]={0};

strncpy(temp,newdata+len-4,4);//從數據串尾部開始 截取4位長


Insert(atoi(temp));// atoi() 將數據轉爲整型後插入 每次都是在頭結點後插入


len=len-4;
}//end while

//執行上述循環後 將剩下的位數做爲一個結點插入
if(len>0&&len<4)
{
char temp[4]={0};

strncpy(temp,newdata,len);

Insert(atoi(temp));

}//end if

}//end if
else//數據不合法的情況 默認值爲0
{
Insert(0);
}


}
//------------------HugeInt類構造函數(參數類型 長整型)----------------------------//
/*
函數名:HugeInt類構造函數
傳入參數:長整型
功能:實現使用長整型初始化類對象
*/
HugeInt::HugeInt(const long k)
{
//定義一空的雙向循環鏈表//
RightEnd=0;
node *temp=new node;
temp->left=temp;
temp->right=temp;
head=temp;
RightEnd=head;
head->data=0;
n=0;
//根據符號設置頭結點值 負數爲1 正數爲0//
if(k<0)
{head->data=1;}
else
{head->data=0;}

//接收傳入的參數並轉爲字符串
char* str=new char[sizeof(k)+1];
itoa(k,str,10);

//如果輸入的數據串合法 則將其分段並存儲在鏈表中//
if(IsRight(str))
{
//取數據串的絕對值
char *newdata=new char[strlen(str)+1];
strncpy(newdata,abs(str),strlen(newdata));
short int len=strlen(newdata);

//當數據的位數大於分段的單位4時 以4位一組作爲結點循環插入到鏈表//
while(len>=4)
{ char temp[5]={0};
strncpy(temp,newdata+len-4,4);//從數據串尾部開始 截取4位
Insert(atoi(temp));// atoi() 將數據轉爲整型後插入 每次都是在頭結點後插入
len=len-4;
}//end while

//執行上述循環後 將剩下的位數做爲一個結點插入
if(len>0&&len<4)
{ char temp[4]={0};
strncpy(temp,newdata,len);//從數據串頭部開始 截取len位
Insert(atoi(temp));
}//end if

}//end if
else//數據不合法的情況 默認值爲0
{
Insert(0);
}

}
//------------------HugeInt類拷貝構造函數----------------------------//
/*
函數名:HugeInt類拷貝構造函數
傳入參數:類對象的引用
功能:實現使用已知類對象初始化類
*/
HugeInt::HugeInt(HugeInt& h)
{ //定義一空的雙向循環鏈表//

n=0;
RightEnd=0;
node *temp=new node;
temp->left=temp;
temp->right=temp;
head=temp;

head->data=h.GetHeadNode()->data;//設置頭結點
RightEnd=head;//設置尾結點

//獲得鏈表各結點值
for(temp=h.RightEnd;temp!=h.GetHeadNode();temp=temp->left)
{
Insert(temp->data);
}

}
/*----------------------------HugeInt類析構函數---------------------------*/
HugeInt::~HugeInt()
{

DelList();//刪除所有結點

delete head;//刪除頭結點

}
/*----------------------------各構造函數的實現[end]---------------------------*/

/*----------------------------各成員函數的實現[begin]---------------------------*/

//------------------插入結點(HugeInt類成員函數)----------------------------//
/*
函數名:Insert
參數: const short int x(常短整型)
返回值:this對象
功能:實現在雙鏈表頭結點(head)後插入新結點
*/
HugeInt& HugeInt::Insert(const short int x)
{//在頭結點後插入新結點

node *temp=new node;
temp->data=x;
temp->left=head;
temp->right=head->right;
head->right->left=temp;
head->right=temp;
n++;

//因每次都是在頭結點後插入新結點 故只需移動一次尾結點 即當n==1時
if(n==1)
{RightEnd=RightEnd->right;}

return *this;
}
//------------------刪除所有結點(HugeInt類成員函數)----------------------------//
void HugeInt::DelList()
{
while(n!=0)
{node *temp=new node;
temp=GetEndNode();
RightEnd=RightEnd->left;

temp->right->left=temp->left;
temp->left->right=temp->right;
delete temp;
n--;
}
}
//------------------求數據串絕對值(重載abs函數)---------------------------//
/*
函數名:abs
傳入參數:char *data (字符指針)
返回值:字符指針
功能:返回數據串的絕對值(如"-563256223354" 返回"563256223354")
*/
char* HugeInt::abs(char *data)
{
char* newdata=new char[strlen(data)+1];
if(data[0]=='-')
{return strncpy(newdata,data+1,strlen(newdata)-1);}//返回不帶負號的數據串
else
return strncpy(newdata,data,strlen(newdata));

}
//-----------------檢驗數據合法性(HugeInt類成員函數)----------------------------------//
/*
函數名:IsRight
傳入參數:char *data (字符指針)
返回值:bool型(true 合法.false非法)
功能:判斷輸入的數據是否合法
說明:在本程序中所謂的合法是指輸入的字符串中的每個字符只能爲數字(0~9)
允許首字符爲"+"與"-"(正負號)
比如合法的字符串: "+0563256","-55115100016","454512053566"等
非法的字符串:"--5632266","df5df12515","dfgjkr"等
*/
bool HugeInt::IsRight(char *data)
{
bool flag=false;//定義是否合法標誌 做爲返回值

if(strlen(data)>MAXLEN)//字符串長度超過定義的最大長度
{ cout<<"字符串長度超過定義的最大長度/n";
return flag;

}//end if

else//字符串長度合法的情況
{
if((data[0]=='-'||data[0]=='+')&&strlen(data)!=1)//判斷首字符
{flag=true;}

if(strlen(data)==1&&data[0]-48>=0&&data[0]-48<=9)//如果爲單字符
{flag=true;}


//如果flag==false 則從第一位開始判斷 否則
//從字符串第二位開始 判斷字符是否爲數字字符//
short int i=flag;
while(i < strlen(data))
{
if(data[i]-48>=0&&data[i]-48<=9)
{flag=true;}
else
{flag=false;break;}//只要發現一個非法字符 則退出循環
i++;

}//end while
if(!flag)
cout<<"[錯誤]數據不合法[數據不合法的情況 本程序返回默認值0]/n";
return flag;
}//end else

}
//------------------------輸出結點(HugeInt類成員函數)------------------------------//
/*
函數名:PrintList
參數:無
返回值:void
功能:實現鏈表的輸出
說明:如數據1265300065632存儲在鏈表中 各結點爲1,2653,6,5632
顯然不能簡單的將結點直接輸出 要補上相應的0
*/
void HugeInt::PrintList()const
{ node *current=new node;
if (head->data==1)//數據串爲負數的情況
{


if(head->right->data!=0)//如果第一個結點不爲0則輸出"-"與該結點數據
{cout<<"-"<< head-> right->data;}
else//如果第一個結點爲0
{
if(head->right->right==head)//如果只有一個結點(也就是0)
{cout<< head->right->data;}//輸出0
else//不止一個結點 需要輸出負號
cout<<"-";
}

}//數據串爲負數的情況結束

else//數據串爲正數的情況
{
//同樣也是先判斷第一個結點的輸出
if((head->right->data!=0))
{cout<<head->right->data;}
else
if(head->right->right==head)//如果只有一個結點(也就是0)
{cout<<head->right->data;}//輸出0

}
bool f=false;//標識在當前結點前是否已有其他結點輸出(也就是當前結點是否是數據串的最高位)
//f=false 表示當前結點是最高位
//從第二個結點開始循環輸出 補上相應個數的零
for(current=head->right->right;current!=head;current=current->right)
{
if(current->left->data!=0||f)//如果當前結點的左結點不爲零或當前結點不是最高位的情況
{ f=true;

//根據結點值補上相應個數的0
if(current->data<=9)//小於9的情況
{cout<<"000"<<current->data;}
else//大於9的情況
{
if(current->data>9 && current->data<=99)
{cout<<"00"<<current->data;}
else
{
if(current->data>99 && current->data<=999)
{cout<<"0"<<current->data;}

if(current->data>999 && current->data<=9999)
{ cout<<current->data;}
}
}//補零操作完成


}

else//當前結點左結點爲零並且當前結點是最高位
{
if(current->data!=0)//該結點值不爲零則輸出
cout<<current->data;
else//該結點值爲零 則只有在鏈表結點個數爲1的情況下輸出(也就是輸出0了)
if(current->right==head)
cout<<current->data;
}

}//for循環結束

}
//*----------------------------各成員函數的實現[end]---------------------------*//

//*----------------------------各運算符重載函數的實現[begin]-------------------*//

//---------------------------------[>]---------------------------------------------------//

//[1]-----------------------重載>(大於 巨型與巨型)-------------------------------//
/*重載運算符:>
參數:類對象引用
返回值:bool型
*/
bool operator>(HugeInt &m,HugeInt &n)
{

if(m.GetHeadNode()->data==1&&n.GetHeadNode()->data==0)//如果m爲負 n爲正則m<n 返回false
{return false;}

else//else 1
{
if(m.GetHeadNode()->data==0&&n.GetHeadNode()->data==1)//如果m爲正 n爲負
{
if(m.IsZero()&&n.IsZero())//m與n等於零的情況
return false;
else//其餘情況返回true
return true;


}
else// else 2
{

if((m.GetHeadNode()->data+n.GetHeadNode()->data)==0)//兩數同正
{ bool flag=false;//標識返回值

//將m,n結點數置成相同
int len=abs(m.GetN()-n.GetN());
if(m.GetN()>n.GetN())
{ for(int i=0;i<len;i++)
n.Insert(0);
}
if(m.GetN()<n.GetN())
{for(int i=0;i<len;i++)
m.Insert(0);
}

//定義兩個結點分別指向m,n的第一個結點
node* mcurrent=new node;
node* ncurrent=new node;
mcurrent=m.GetHeadNode()->right;
ncurrent=n.GetHeadNode()->right;

//從第一個結點開始比較m,n的對應結點
while(mcurrent!=m.GetHeadNode())
{
if(mcurrent->data>ncurrent->data)//如果m的當前結點值大於n則退出循環 返回true
{flag=true;break;}
else
if(mcurrent->data<ncurrent->data)//如果m的當前結點值小於n則退出循環 返回true
{flag=false;break;}
else//當前值相等的情況 繼續下一結點比較
{mcurrent=mcurrent->right;ncurrent=ncurrent->right;}

}
return flag;
}//兩數同爲正的情況結束

else//兩數同爲負的情況 進行兩數絕對值的比較
{
return abs(n)>abs(m);

}

}//end else 2

}//end else 1


}

//[2]-----------------------重載>(大於 巨型與長整型)-----------------------------//
bool operator>(HugeInt &m,const long int &n)
{ //先進行類型轉換 再比較
return m>HugeInt(n);
}
//[3]-----------------------重載>(大於 長整型與巨型)-----------------------------//
bool operator>(const long int &m,HugeInt &n)
{ //先進行類型轉換 再比較
return HugeInt(m)>n;
}
//[4]-----------------------重載>(大於 巨型與字符型)-----------------------------//
bool operator>(HugeInt &m, char* n)
{ //先進行類型轉換 再比較
return m>HugeInt(n);
}
//[5]-----------------------重載>(大於 字符型與巨型)--------------------------------//
bool operator>( char* m,HugeInt &n)
{ //先進行類型轉換 再比較
return HugeInt(m)>n;
}


//------------------------------[<]-------------------------------------------------------//

//[1]---------------------重載<(小於 巨型與字符型比較)--------------------------------//
bool operator<(HugeInt &m, char* n)
{ //先進行類型轉換 再根據已重載的運算符(>)進行比較
HugeInt temp(n);
return (m>temp||m==temp)?false:true;
}
//[2]---------------------重載<(小於 字符型與巨型比較)-------------------------------//
bool operator<( char* m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>)進行比較
HugeInt temp(m);
return (temp>n||temp==n)?false:true;
}
//[3]---------------------重載<(小於 巨型與長整型比較)-------------------------------//
bool operator<(HugeInt &m,const long int &n)
{ //先進行類型轉換 再根據已重載的運算符(>)進行比較
HugeInt temp(n);
return (m>temp||m==temp)?false:true;
}
//[4]---------------------重載<(小於 長整型與巨型比較)------------------------------//
bool operator<(const long int &m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>)進行比較
HugeInt temp(m);
return (temp>n||temp==n)?false:true;
}
//[5]---------------------重載<(小於 巨型與巨型比較)--------------------------------//
bool operator<(HugeInt &m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>)進行比較
return (m>n||m==n)?false:true;
}


//-----------------------------[==]-----------------------------------------------------//

//[1]-------------------重載==(等於 巨型與巨型比較)--------------------------------//
/*重載運算符:==
參數:類對象引用
返回值:bool型
*/
bool operator==(HugeInt &m,HugeInt &n)
{

bool flag=false;

//如果m,n不爲零並且異號 返回false
if((m.GetHeadNode()->data!=n.GetHeadNode()->data)&&!m.IsZero()&&!n.IsZero())
{flag=false;}

else
{
//將m,n結點數置成相同
int len=abs(m.GetN()-n.GetN());
if(m.GetN()>n.GetN())
{ for(int i=0;i<len;i++)
n.Insert(0);
}
if(m.GetN()<n.GetN())
{for(int i=0;i<len;i++)
m.Insert(0);
}

//定義兩個結點分別指向m,n的第一個結點
node* mcurrent=new node;
node* ncurrent=new node;
mcurrent=m.GetHeadNode()->right;
ncurrent=n.GetHeadNode()->right;

while(mcurrent!=m.GetHeadNode())//從第一個結點開始對應比較
{
if(mcurrent->data!=ncurrent->data)//如果發現不等則退出循環
{flag=false;break;}
else//其他情況繼續進行下一結點比較
{flag=true;mcurrent=mcurrent->right;ncurrent=ncurrent->right;}


}//end while


}//end else
return flag;

}
//[2]-------------------重載==(等於 巨型與長整型比較)--------------------------------//
bool operator==(HugeInt &m,const long int &n)
{ //先進行類型轉換 再比較
return m==HugeInt(n);
}
//[3]-------------------重載==(等於 長整型與巨型比較)--------------------------------//
bool operator==(const long int &m,HugeInt &n)
{ //先進行類型轉換 再比較
return HugeInt(m)==n;
}
//[4]-------------------重載==(等於 巨型與字符型比較)--------------------------------//
bool operator==(HugeInt &m,char* n)
{ //先進行類型轉換 再比較
return m==HugeInt(n);
}
//[5]-------------------重載==(等於 字符型與巨型比較)--------------------------------//
bool operator==(char* m,HugeInt &n)
{ //先進行類型轉換 再比較
return HugeInt(m)==n;
}


//--------------------------------[>=]----------------------------------------------------//

//[1]-------------------------重載>=(大於等於 巨型與字符型)------------------------------//

bool operator>=(HugeInt &m,char* n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(n);
return (m>temp||m==temp);

}
//[2]-------------------------重載>=(大於等於 字符型與巨型)-----------------------------//
bool operator>=(char* m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(m);
return (temp>n||temp==n);

}
//[3]-------------------------重載>=(大於等於 巨型與長整型)-----------------------------//

bool operator>=(HugeInt &m,const long int &n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(n);
return (m>temp||m==temp);

}
//[4]-------------------------重載>=(大於等於 長整型與巨型)-----------------------------------//
bool operator>=(const long int &m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(m);
return (temp>n||temp==n);

}
//[5]-------------------------重載>=(大於等於 巨型與巨型)-----------------------------------//
bool operator>=(HugeInt &m,HugeInt &n)
{ //根據已重載的運算符(>,==)進行比較
return (m>n||m==n);

}


//--------------------------------[<=]---------------------------------------------------//

//[1]-------------------------重載<=(小於等於 字符型與巨型)------------------------//
bool operator<=(char* m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(m);
return (temp<n||temp==n);

}
//[2]-------------------------重載<=(小於等於 巨型與字符型)------------------------//
bool operator<=(HugeInt &m,char* n)
{ //先進行類型轉換 再根據已重載的運算符(<,==)進行比較
HugeInt temp(n);
return (m<temp||m==temp);

}
//[3]-------------------------重載<=(小於等於 長整型與巨型)-----------------------//
bool operator<=(const long int &m,HugeInt &n)
{ //先進行類型轉換 再根據已重載的運算符(>,==)進行比較
HugeInt temp(m);
return (temp<n||temp==n);

}
//[4]-------------------------重載<=(小於等於 巨型與長整型)----------------------//
bool operator<=(HugeInt &m,const long int &n)
{ //先進行類型轉換 再根據已重載的運算符(<,==)進行比較
HugeInt temp(n);
return (m<temp||m==temp);

}
//[5]-------------------------重載<=(小於等於 巨型與巨型)-----------------------//
bool operator<=(HugeInt &m,HugeInt &n)
{ //根據已重載的運算符(<,==)進行比較
return (m<n||m==n);
}


//-----------------------------[!=]-----------------------------------------------//

//[1]-------------------------重載!=(不等於 字符型與巨型)-----------------------//
bool operator!=(char* m,HugeInt &n)
{ //先進行類型轉換 根據已重載的運算符(!,==)進行比較
return (!(HugeInt(m)==n));

}
//[2]-------------------------重載!=(不等於 巨型與字符型)------------------------//
bool operator!=(HugeInt &m,char* n)
{ //先進行類型轉換 根據已重載的運算符(!,==)進行比較
return (!(m==HugeInt(n)));

}
//[3]-------------------------重載!=(不等於 長整型與巨型)-------------------------//
bool operator!=(const long int m,HugeInt &n)
{ //先進行類型轉換 根據已重載的運算符(!,==)進行比較
return (!(HugeInt(m)==n));

}
//[4]-------------------------重載!=(不等於 巨型與長整型)------------------------//
bool operator!=(HugeInt &m,const long int n)
{ //先進行類型轉換 根據已重載的運算符(!,==)進行比較
return (!(m==HugeInt(n)));

}
//[5]-------------------------重載!=(不等於 巨型與巨型)--------------------------//
bool operator!=(HugeInt &m,HugeInt &n)
{ // 根據已重載的運算符(!,==)進行比較
return (!(m==n));

}

//--------------------------重載<<(輸出)--------------------------------------//
ostream &operator<<(ostream &out,HugeInt &m)
{ m.PrintList();//調用PrintList()函數輸出各結點
return out;
}

//-----------------------------------[-]---------------------------------------------//

//[1]-------------------------重載-(減法 字符型與巨型)----------------------------//
HugeInt operator -(char* minuend,HugeInt& subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-)進行運算
return HugeInt(minuend)-subtrahend;
}

//[2]-------------------------重載-(減法 巨型與字符型)---------------------------//
HugeInt operator -(HugeInt& minuend,char* subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-)進行運算
return minuend-HugeInt(subtrahend);
}
//[3]-------------------------重載-(減法 長整型與巨型)---------------------------//
HugeInt operator -(const long int& minuend,HugeInt& subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-)進行運算
return HugeInt(minuend)-subtrahend;
}
//[4]-------------------------重載-(減法 巨型與長整型)--------------------------//
HugeInt operator -(HugeInt& minuend,const long int& subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-)進行運算
return minuend-HugeInt(subtrahend);
}
//[5]-------------------------重載-(減法 巨型與巨型)---------------------------//
/*重載運算符:-
參數:類對象引用(minuend 被減數,subtrahend 減數)
返回值:類對象
*/
HugeInt operator -(HugeInt& minuend,HugeInt& subtrahend)
{
if((minuend.GetHeadNode()->data+subtrahend.GetHeadNode()->data)==0)//同爲正數的情況
{
if(minuend>=subtrahend)//被減數大於減數
{
//新建結點並指向兩數尾結點
node* curmin=new node;
curmin=minuend.GetEndNode();
node* cursub=new node;
cursub=subtrahend.GetEndNode();

//將減數與被減數結點數置成相同
int len=abs(minuend.GetN()-subtrahend.GetN());
if(minuend.GetN()>subtrahend.GetN())
{
for(int i=0;i<len;i++)
subtrahend.Insert(0);
}
if(minuend.GetN()<subtrahend.GetN())
{
for(int i=0;i<len;i++)
minuend.Insert(0);
}

//做兩正數的減操作//
HugeInt sub;//存放相減結果
short int borrow=0;//標識借位
while(curmin!=minuend.GetHeadNode())//從尾結點開始兩結點數據做減操作
{
if(curmin->data-borrow-cursub->data>=0)//如果被減數夠減
{
sub.Insert(curmin->data-borrow-cursub->data);//將相減結果存入結果鏈表中
borrow=0;//標識借位爲0(沒有借位)

}
else//有借位情況
{
//相減結果爲負,將結果加上10000(一個結點四位)並存入結果鏈表中//
sub.Insert(curmin->data-borrow-cursub->data+10000);//
borrow=1;//標識借位爲1(表示借值10000)
}

curmin=curmin->left;//被減數指向前一結點
cursub=cursub->left;//減數指向前一結點

}//while結束
return sub;

}

else//被減數小於減數
{
return -(abs(subtrahend)-abs(minuend));//返回絕對值差的相反數
}



}//if結束(同爲正數的情況結束)

else
{
if((minuend.GetHeadNode()->data+subtrahend.GetHeadNode()->data)==2)//如果同爲負數
{
if(abs(minuend)>abs(subtrahend))//被減數絕對值大於減數絕對值
{
return -(abs(minuend)-abs(subtrahend));

}
else
{
return abs(subtrahend)-abs(minuend);
}

}
else
{ //一正一負的情況[轉爲正數加法]

if(minuend>subtrahend)
{
return (abs(minuend)+abs(subtrahend));
}
else
{
return -(abs(subtrahend)+abs(minuend));
}


}//一正一負的情況結束

}//end else



}

//--------------重載abs(求絕對值)---------------------------------------------//
/*重載運算符:abs
參數:類對象
返回值:類對象
*/
HugeInt abs(HugeInt h)
{
h.SetHeadData(0);//設置頭結點數據爲0(表示正數)
return h;

}
//---------------重載-(求反)----------------------------------------------------//
/*重載運算符:-
參數:HugeInt對象
返回值:HugeInt對象
*/
HugeInt operator-(HugeInt h)
{

(h.GetHeadNode()->data==0)?h.SetHeadData(1):h.SetHeadData(0);//將數據符號置反

return h;

}

//------------------------------------[+]---------------------------------------------//

//[1]-----------------重載+(加法 巨型與巨型)-------------------------------//
HugeInt operator +(HugeInt& addend,HugeInt& augend)
{

if((addend.GetHeadNode()->data+augend.GetHeadNode()->data)==0)//同爲正數的情況

{

if(addend.GetN()>=augend.GetN())//如果被加數的結點數大於加數
{
//新建兩個結點分別指向被加數與加數尾結點
node* curadd=new node;
curadd=addend.GetEndNode();
node* curaug=new node;
curaug=augend.GetEndNode();

HugeInt sum;//標識和
int carry=0;//標識進位

//從加數尾結點開始循環 讓每個結點與被加數的對應結點相加
//比如被加數1,2345,6789,加數:2345,6789
while(curaug!=augend.GetHeadNode())
{

sum.Insert((curadd->data+curaug->data+carry)%10000);//sum對應結點的值

carry=(curadd->data+curaug->data+carry)/10000;//設置進位

curaug=curaug->left;
curadd=curadd->left;
}
//處理剩下的被加數結點 如上述兩個數 對應結點相加後還剩結點1
while(curadd!=addend.GetHeadNode())
{
sum.Insert((curadd->data+carry)%10000);

carry=(curadd->data+carry)/10000;
curadd=curadd->left;

}
if(carry!=0)//全部加完還有進位
{sum.Insert(carry); }
return sum;

}
else
{
return augend+addend;//執行加數+被加數
}


}//同爲正數的情況結束
else
{ if((addend.GetHeadNode()->data+augend.GetHeadNode()->data)==2)//如果同爲負數

{
return -(abs(addend)+abs(augend));

}
else//[一正一負情況(轉爲減法處理)]
{ if(addend>augend)
return addend-abs(augend);
else
return augend-abs(addend);

}

}
}
//[2]-----------------重載+(加法 巨型與長整型)------------------------------------------------------//
HugeInt operator +(HugeInt& addend,const long int& augend)
{ //先進行類型轉換 再根據已重載的運算符(+)進行運算
return HugeInt(augend)+addend;

}
//[3]-----------------重載+(加法 長整型與巨型)------------------------------------------------------//
HugeInt operator +(const long int& addend,HugeInt& augend)
{ //先進行類型轉換 再根據已重載的運算符(+)進行運算
return HugeInt(addend)+augend;

}
//[4]-----------------重載+(加法 巨型與字符型)------------------------------------------------------//
HugeInt operator +(HugeInt& addend,char* augend)
{ //先進行類型轉換 再根據已重載的運算符(+)進行運算
return HugeInt(augend)+addend;

}
//[5]-----------------重載+(加法 字符型與巨型)------------------------------------------------------//
HugeInt operator +(char* addend,HugeInt& augend)
{ //先進行類型轉換 再根據已重載的運算符(+)進行運算
return HugeInt(addend)+augend;

}

//---------------------------------[+=]-------------------------------------------------//

//[1]-----------------------------重載+=()------------------------------------------//
HugeInt& HugeInt::operator +=(HugeInt& augend)
{ //根據已重載的運算符(+,=)進行運算
*this=*this+augend;
return *this;
}
//[2]-----------------------------重載+=()------------------------------------------//
HugeInt& HugeInt::operator +=(const long int& augend)
{ //先進行類型轉換 根據已重載的運算符(+,=)進行運算
*this=*this+HugeInt(augend);
return *this;
}
//[3]-----------------------------重載+=()------------------------------------------//
HugeInt& HugeInt::operator +=(char* augend)
{ //先進行類型轉換 根據已重載的運算符(+,=)進行運算
*this=*this+HugeInt(augend);
return *this;
}

//--------------------------------------[-=]------------------------------------------//

//[1]-----------------------------重載-=()------------------------------------------//
HugeInt& HugeInt::operator -=(HugeInt& subtrahend)
{ //根據已重載的運算符(-,=)進行運算
*this=*this-subtrahend;
return *this;
}
//[2]-----------------------------重載-=()------------------------------------------//
HugeInt& HugeInt::operator -=(const long int& subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-,=)進行運算
*this=*this-HugeInt(subtrahend);
return *this;
}
//[3]-----------------------------重載-=()------------------------------------------//
HugeInt& HugeInt::operator -=(char* subtrahend)
{ //先進行類型轉換 根據已重載的運算符(-,=)進行運算
*this=*this-HugeInt(subtrahend);
return *this;
}

//------------------------------------[=]---------------------------------------------//

//[1]-----------------------------重載=()------------------------------------------//
HugeInt& HugeInt::operator =(const long int& k)
{ *this=HugeInt(k);//先進行類型轉換,再調用拷貝構造函數 實現對象賦值

return *this;
}
//[2]-----------------------------重載=()------------------------------------------//
HugeInt& HugeInt::operator =(char* k)
{ *this=HugeInt(k);//先進行類型轉換,再調用拷貝構造函數 實現對象賦值

return *this;
}

//[3]-----------------------------重載=()------------------------------------------//
/*
說明:對象與對象之間本是可以直接賦值 但考慮到有指針類型成員的存在
所以需要重載=與拷貝構造函數
*/
HugeInt& HugeInt::operator =(HugeInt& h)
{
HugeInt newh(h);
DelList();//刪除已有結點

//循環執行值拷貝
node *current=new node;
current=newh.GetEndNode();
while(current!=newh.GetHeadNode())
{
Insert(current->data);
current=current->left;

}

SetHeadData(newh.GetHeadNode()->data);//設置頭結點
return *this;
}


//------------------------++(前++)-------------------------------//
HugeInt& HugeInt::operator ++()
{ //當前對象加1後返回當前對象
*this+=1;
return *this;

}

//------------------------++(後++)-------------------------------//
HugeInt HugeInt::operator ++(int)
{
HugeInt temp=*this;//建立臨時對象保存當前對象值
*this+=1;//當前對象值加1
return temp;//返回臨時對象

}

//---------------------------(前--)-------------------------------//
HugeInt& HugeInt::operator --()
{ //當前對象減1後返回當前對象
*this-=1;
return *this;

}

//--------------------------(後--)-------------------------------//
HugeInt HugeInt::operator --(int)
{
HugeInt temp=*this;//建立臨時對象保存當前對象值
*this-=1;//當前對象值減1
return temp;//返回臨時對象

}

//---------------------------------[*=]----------------------------------------------//

//[1]-----------------------乘等於(巨型與字符型)----------------------------------//
HugeInt& HugeInt::operator *=(char* faciend)
{ //先進行類型轉換 再根據已重載的運算符(*,=)進行運算
*this=*this*HugeInt(faciend);
return *this;
}
//[2]-----------------------乘等於(巨型與長整型)----------------------------------//
HugeInt& HugeInt::operator *=(const long int& faciend)
{ //先進行類型轉換 再根據已重載的運算符(*,=)進行運算
*this=*this*HugeInt(faciend);
return *this;
}
//[3]-----------------------乘等於(巨型與巨型)----------------------------------//
HugeInt& HugeInt::operator *=(HugeInt& faciend)
{ //先進行類型轉換 再根據已重載的運算符(*,=)進行運算
*this=*this*faciend;
return *this;
}

//----------------------------------------[*]---------------------------------------//

//[1]-----------------------乘法(字符型與巨型)----------------------------------//
HugeInt operator *(char* faciend,HugeInt& multiplicator)
{ //先進行類型轉換 再根據已重載的運算符(*)進行運算
return HugeInt(faciend)*multiplicator;
}
//[2]-----------------------乘法(巨型與字符型)----------------------------------//
HugeInt operator *(HugeInt& faciend,char* multiplicator)
{ //先進行類型轉換 再根據已重載的運算符(*)進行運算
return faciend*HugeInt(multiplicator);
}

//[3]-----------------------乘法(長整型與巨型)----------------------------------//
HugeInt operator *(const long int& faciend,HugeInt& multiplicator)
{ //先進行類型轉換 再根據已重載的運算符(*)進行運算
return HugeInt(faciend)*multiplicator;
}
//[4]-----------------------乘法(巨型與長整型)----------------------------------//
HugeInt operator *(HugeInt& faciend,const long int& multiplicator)
{ //先進行類型轉換 再根據已重載的運算符(*)進行運算
return faciend*HugeInt(multiplicator);
}
//[5]-----------------------乘法(巨型與巨型)----------------------------------//
/*重載運算符:*
參數:類對象引用(faciend 被乘數,multiplicator 乘數)
返回值:類對象
備註(主思想):總是讓結點數多的數當任被乘數 循環讓乘數的每一結點與被乘數的所有結點相乘
*/
HugeInt operator *(HugeInt& faciend,HugeInt& multiplicator)
{
HugeInt product;//兩數相乘的積

node* curmul=new node;//新建一結點指向乘數的尾結點
curmul=multiplicator.GetEndNode();

if(faciend.GetN()>=multiplicator.GetN())//如果被乘數的位數大於等於乘數
{

short int count=0;//表示當前結點前已經與被乘數相乘過的結點數
while(curmul!=multiplicator.GetHeadNode())//從乘數尾結點開始向左掃描
{
short int carry=0;//標識進位
HugeInt temp;//建立一臨時對象 存放臨時的積(一個乘數結點與被乘數相乘後的積)

for(int i=0;i<count;i++)
{temp.Insert(0);}

node* curfac=new node;//新建一結點指向被乘數的尾結點
curfac=faciend.GetEndNode();

while(curfac!=faciend.GetHeadNode())//從被乘數尾結點開始向左掃描
{
temp.Insert((curmul->data*curfac->data+carry)%10000);//得到結點值

carry=(curmul->data*curfac->data+carry)/10000;//得到進位

curfac=curfac->left;//被減數結點左移
}//while循環結束
if(carry!=0)//如果還有進位
{temp.Insert(carry);}

product+=temp;//賦給最終積對象


count++;//表示執行完一個乘數結點與被乘數所有結點的相乘運算

curmul=curmul->left;//乘數結點左移

}//while循環結束

if((faciend.GetHeadNode()->data+multiplicator.GetHeadNode()->data)==1) //如果兩數異號
return -product;
else//如果兩數同號

return product;

}//如果被乘數的位數大於乘數情況結束

else//如果被乘數的位數小於乘數 則反過來乘
{
return multiplicator*faciend;

}
}



//-------------------------------------[%]---------------------------------------------//

//[1]------------------------%(求餘 巨型與字符型)------------------------------//
HugeInt operator %(HugeInt dividend,char* divisor)
{ //先進行類型轉換 再根據已重載的運算符(%)進行運算
return dividend%HugeInt(divisor);
}
//[2]------------------------%(求餘 字符型與巨型)------------------------------//
HugeInt operator %(char* dividend,HugeInt divisor)
{ //先進行類型轉換 再根據已重載的運算符(%)進行運算
return HugeInt(dividend)%divisor;
}
//[3]------------------------%(求餘 巨型與長整型)------------------------------//
HugeInt operator %(HugeInt dividend,const long int divisor)
{ //先進行類型轉換 再根據已重載的運算符(%)進行運算
return dividend%HugeInt(divisor);
}
//[4]------------------------%(求餘 長整型與巨型)------------------------------//
HugeInt operator %(const long int dividend,HugeInt divisor)
{ //先進行類型轉換 再根據已重載的運算符(%)進行運算
return HugeInt(dividend)%divisor;
}
//[5]------------------------%(求餘 巨型與巨型)------------------------------//
/*重載運算符:%
參數:類對象(dividend 被除數, divisor 除數)
返回值:類對象
*/
HugeInt operator %(HugeInt dividend,HugeInt divisor)
{
if(divisor!="0")//如果除數不爲零

{
HugeInt newdividend=abs(dividend);//被除數的絕對值
HugeInt newdivisor=abs(divisor);//除數的絕對值
HugeInt quo;//商
HugeInt residual;//餘數
if(newdividend>newdivisor)//被除數的絕對值大於除數的絕對值
{ //short int mulcount=0;
quo=newdividend/newdivisor;//進行"/"運算
residual=newdividend-newdivisor*quo;//求餘

}
else//被除數的絕對值小於除數的絕對值
{ residual=newdividend;//餘數爲被除數
}

//根據被除數符號返回相應值(餘數符號跟被除數符號相同 與除數符號無關)
if(dividend.GetHeadNode()->data==0)
{
return residual;
}
else
{
return -residual;
}


}//除數不爲零的情況結束

else//除數爲零的情況
{ cout<<"[輸入錯誤]除數不能爲零/n";
return HugeInt("0");
}

}
//-----------------------------------[%=]---------------------------------------//

//[1]------------------------%=(求餘等於)------------------------------//
HugeInt& HugeInt::operator %=(char* div)
{
//根據已重載的運算符(%,=)進行運算
*this=*this%HugeInt(div);
return *this;
}
//[2]------------------------%=(求餘等於)------------------------------//
HugeInt& HugeInt::operator %=(HugeInt& div)
{
//根據已重載的運算符(%,=)進行運算
*this=*this%div;
return *this;
}
//[3]------------------------%=(求餘等於)------------------------------//
HugeInt& HugeInt::operator %=(const long int& div)
{ //先進行類型轉換 再根據已重載的運算符(%,=)進行運算
*this=*this%HugeInt(div);
return *this;
}
//---------------------------------[/=]------------------------------------------------//

//[1]------------------------/=(除等於 巨型與巨型)------------------------------//
HugeInt& HugeInt::operator /=(HugeInt& dividend)
{ // 根據已重載的運算符(/,=)進行運算
*this=*this/dividend;
return *this;
}
//[2]------------------------/=(除等於 巨型與長整型)------------------------------//
HugeInt& HugeInt::operator /=(const long int& dividend)
{ //先進行類型轉換 再根據已重載的運算符(/,=)進行運算
*this=*this/HugeInt(dividend);
return *this;
}
//[3]------------------------/=(除等於 巨型與字符型)------------------------------//
HugeInt& HugeInt::operator /=(char* dividend)
{ //先進行類型轉換 再根據已重載的運算符(/,=)進行運算
*this=*this/HugeInt(dividend);
return *this;
}

//----------------------------------------------[/]-----------------------------------//

//[1]-----------------/(除法 字符型與巨型)---------------//
HugeInt operator /(char* dividend,HugeInt divisor)
{ //先進行類型轉換 再根據已重載的運算符(/)進行運算
return HugeInt(dividend)/divisor;
}
//[2]-----------------/(除法 巨型與字符型)--------------//
HugeInt operator /(HugeInt dividend,char* divisor)
{ //先進行類型轉換 再根據已重載的運算符(/)進行運算
return dividend/HugeInt(divisor);
}
//[3]------------------------/(除法 長整型與巨型)-----------//
HugeInt operator /(const long int dividend,HugeInt divisor)
{ //先進行類型轉換 再根據已重載的運算符(/)進行運算
return HugeInt(dividend)/divisor;
}
//[4]-------------------------/(除法 巨型與長整型)----------//
HugeInt operator /(HugeInt dividend,const long int divisor)
{ //先進行類型轉換 再根據已重載的運算符(/)進行運算
return dividend/HugeInt(divisor);
}
//[5]-------------------------/(除法 巨型與巨型)------------//
/*重載運算符:/
參數:類對象(dividend 被除數, divisor 除數)
返回值:類對象
備註:
(算法舉例)
比如要算9999/20吧,因爲9999>20,先將20擴大10倍(擴大2次後爲2000 再擴大就比9999大了),
然後9999-2000相減(減4次 因爲再減下去就是負數了)得到結果1999,
現在先把得到的第一位商存起來(第一位商就是4擴大10倍 兩次 也就是400);
接着因爲1999比20大,再將20擴大10倍(擴大1次得到200),
做1999-200,(減8次 )結果爲399,得到第二位商80(8擴大10倍 1次),
現在399比20大,繼續擴大除數(這個擴大1次 爲200),做399-200(做1次),
結果爲199,得到第三位商10(1擴大10倍1次),現在199比20大,但20不用在擴大了,
再擴大10倍的話就比199大了,做199-20(減9次 減後爲19),因爲這次除數沒有擴大,
所以得到的第四位商就是9(9無需再擴大10倍多少次),現在減後的結果是19,19〈20,
就不要再算了,將得到的四次商加起來400+80+10+9=499,就是9999/20的商了
*/
HugeInt operator /(HugeInt dividend,HugeInt divisor)
{
if(divisor!="0")//如果除數不爲零

{ //先轉化爲絕對值進行運算
HugeInt newdividend=abs(dividend);
HugeInt newdivisor=abs(divisor);
HugeInt quotient;//商

if(newdividend<newdivisor)//被除數小於除數 返回0
{ return quotient;
}
while(newdividend>=newdivisor)//被除數大於等於除數
{
HugeInt tempquo;//存放每次上商的值
short int mulcount=0;//標識除數擴大的次數(10倍10倍地擴大)
HugeInt temp=newdivisor;//建立臨時對象 值爲當前的除數

//先擴大除數
//噹噹前的除數小於被除數並且擴大10被後還是小於被除數 則繼續擴大除數
while((temp<newdividend)&&((temp*10)<newdividend))
{ temp*=10;
mulcount++;//每擴大一次 次數加一
}

//經過上述擴大,執行被除數與除數(擴大後的除數)減操作 直到被除數爲零或小於除數
while(newdividend!="0"&&(newdividend)>=temp)
{ newdividend-=temp;
tempquo++;//每減一次 上商的值加一
}

//根據除數擴大的次數 將上商的值擴大相同次數
while(mulcount!=0)
{ tempquo*=10;
mulcount--;
}

quotient+=tempquo;//將上商的值賦給最終的商
}//循環結束

//下面再根據符號判斷返回值
if(dividend.GetHeadNode()->data+divisor.GetHeadNode()->data!=1)
{
return quotient;
}
else
{
return -quotient;
}


}//除數不爲零的情況結束

else//除數爲零的情況
{
cout<<"[輸入錯誤]除數不能爲零/n";
return HugeInt("0");
}



}
//*----------------------------各重載函數的實現[end]------------------------------*//

//-------------------------------主函數(測試函數)------------------------------------------//

//說明:若在編譯時提示測試函數錯誤,前檢查您的程序是否按要求重載了所需的運算符
//沒有重載的話請註釋掉部分測試程序

void main()
{


//---------人工檢測部分-----//

//------------檢測是否有對輸入的字符串進行驗證-------------//
cout<<"//-----------------[檢測任務1]檢測是否有對輸入的字符串進行驗證--------------///n";
cout<<"[測試用例]使用字符串-a5553,a,1a, ,+a創建對象/n";
HugeInt test1("-a5553");
HugeInt test2("a");
HugeInt test3("1a");
HugeInt test4("");
HugeInt test5("+a");
cout<<"[正確值]應該設置出錯提示或有容錯功能以便程序能繼續運行"<<endl;
//------------檢測是否定義所要求的構造函數----------------//
cout<<"/n//-----------------[檢測任務2]檢測是否定義所要求的構造函數-----------------///n";
HugeInt test6("+0");
HugeInt test7("-0");
HugeInt test8(-220580243);
HugeInt test9("123456789123456789123456789123456789123456789");
HugeInt test10("012");
HugeInt test11("-0012000300800");
HugeInt test12("0000000012");
cout<<"輸出值如下/n"<<test6<<" "<<test7<<" "<<test8<<" "<<test9<<" "<<test10<<" "<<test11<<" "<<test12<<endl;
cout<<"[正確值]如下/n"<<"0 0 -220580243 123456789123456789123456789123456789123456789 12 -12000300800 12/n";
//---------------檢測邏輯運算符是否正確重載--------------//
cout<<"/n//-----------------[檢測任務3]檢測邏輯運算符是否正確重載-----------------///n";
cout<<"執行0>0輸出"<<(test6>test7)<<"[正確值0]/n";
cout<<"執行0==0輸出"<<(test6==test7)<<"[正確值1]/n";
cout<<"執行0>-220580243輸出"<<(test6>test8)<<"[正確值1]/n";
cout<<"執行-220580243<-0012000300800輸出"<<(test8<test11)<<"[正確值0]/n";
cout<<"執行123456789123456789123456789123456789123456789<012輸出"<<(test9<test10)<<"[正確值0]/n";
cout<<"執行0!=0輸出"<<(test6!=test7)<<"[正確值0]/n";
cout<<"執行0>=0輸出"<<(test6>=test7)<<"[正確值1]/n";
cout<<"執行012==0000000012輸出"<<(test10==test12)<<"[正確值1]/n";
cout<<"執行0000000012<012輸出"<<(test12<test10)<<"[正確值0]/n";

//---------機器檢測--------//

//---------------檢測對象間能否正確賦值--------------//
cout<<"/n//-----------------[檢測任務4]檢測對象間能否正確賦值-----------------///n";
HugeInt test13("9876543210123456789");
HugeInt test14;
test14=test13;
HugeInt test15(test14);
if((test13==test14)&&(test14==test15))
{cout<<"通過檢測任務4/n";}
else
{ cout<<"未通過檢測任務4/n";
}
//----------------檢測(+,-*,/,%)是否正確重載---------------------------------//
cout<<"/n//-----------------[檢測任務5]檢測(+,-*,/,%)是否正確重載------------------///n";
cout<<"[測試用例] 表達式y=a+b*c-d/e/n";
HugeInt a(-419);
HugeInt b("10002000300040005000");
HugeInt c("-999999990001");
HugeInt d("9876543210");
HugeInt e("-110120119");
HugeInt y=(a+b*c-d/e);
cout<<"初始化:/n";
cout<<"a=-419/nb=10002000300040005000/nc=-999999990001/nd=9876543210/ne=-110120119";
cout<<"/n進入測試/n";
bool flag=false;
if(a!=(y-b*c+d/e))
{ cout<<"[發現錯誤]在執行表達式a==(y-b*c+d/e)時/n";
flag=true;
}
else
{cout<<"執行表達式a==(y-b*c+d/e)通過/n";
}
if((b*c)!=(y-a+d/e))
{ flag=true;
cout<<"[發現錯誤]在執行表達式(b*c)==(y-a+d/e)時/n";
}
else
{cout<<"執行表達式(b*c)!=(y-a+d/e)通過/n";
}
if((c*b-d/e)!=(y-a))
{ flag=true;
cout<<"[發現錯誤]在執行表達式(c*b-d/e)!=(y-a)時/n";
}
else
{cout<<"執行表達式(c*b-d/e)!=(y-a)通過/n";
}
if((d-d%e)!=(a+b*c-y)*e)
{ flag=true;
cout<<"[發現錯誤]在執行表達式(d-d%e)!=(a+b*c-y)*e時/n";
}
else
{cout<<"執行表達式(d-d%e)!=(a+b*c-y)*e通過/n";
}
if((a+b*c-y)!=(d/e))
{ flag=true;
cout<<"[發現錯誤]在執行表達式(y-a-b*c)!=d/e時/n";
}
else
{cout<<"執行表達式(a+b*c-y)!=(d/e)通過/n";
}
if(!flag)
{cout<<"通過檢測任務5/n";}
else
{cout<<"未通過檢測任務5/n";
}
//----------------檢測(+=,-=,*=,/=,%=)是否正確重載---------------------------------//
//若計算表達式y=y+a+b*c-d/e後y值
//與計算表達式(d%=e;c/=d;b*=c;a-=b;y+=a;)後y值相同則通過測試//
cout<<"/n//--------------[檢測任務6]檢測(+=,-=,*=,/=,%=)是否正確重載----------------///n";
cout<<"[測試用例] 表達式y=y+a+b*c-d/e/n";
HugeInt source(y+(a-b*(c/(d%e))));
d%=e;
c/=d;
b*=c;
a-=b;
y+=a;
if(y==source)
{cout<<"通過檢測任務6/n";
}
else
{cout<<"未通過檢測任務6/n";
}

//----------------檢測(++,--)是否正確重載---------------------------------//
cout<<"/n//-----------------[檢測任務7]檢測(++,--)是否正確重載------------------///n";
HugeInt f("1000000000000");
HugeInt g("999999999999");
if((f--)==(++g)&&(--g)==(--(++f)))
{cout<<"通過檢測任務7/n";}
else
{cout<<"未通過檢測任務7/n";
}

//----------------檢測巨型跟整型是否正確運算---------------------------------//
cout<<"/n//-----------------[檢測任務8]檢測巨型跟整型是否正確運算------------------///n";

int i=rand();//產生隨機數
HugeInt mynum("220580243");
bool isok=true;
if(mynum!=mynum+i-i)
{ isok=false;
}
if(mynum!=mynum*i/i+mynum*i%i)
{ isok=false;
}
if(isok)
{cout<<"通過檢測任務8/n";
}
else
{cout<<"未通過檢測任務8/n";
}

//----------------檢測50位以上巨型相乘運算---------------------------------//
cout<<"/n//-----------------[檢測任務9]檢測50位以上巨型相乘運算------------------///n";
HugeInt num("220580243220580243220580243220580243220580243220580243220580243");
if(num==num*1)
{cout<<"通過檢測任務9/n";
}
else
{cout<<"未通過檢測任務9/n";
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章