BIgnum类的程序提交
日期:2018.7.19
星期四
博客期:002
这之前赶着做一个单机游戏的修改器忘了时间,不好意思啊!今天我就把Bignum类的源代码发出来,文件的话,我不知道怎样发,待我好好研究研究这个网站哈!因为内容实在是太大了!我就不排版了啊!
//===================》如下为 main.cpp 文件
#include<iostream>
using namespace std;
#include<Windows.h>
#include"Basic.h"
#include"Bignum.h"
Bignum touch1,touch2;
void win0()
{
system("cls");
Basic::pend();
Basic::make_an_char("Basic Class Practise",'*',1,2,2);
Basic::pend();
Basic::pend(' ');
Basic::pend('=',28);
Basic::pend();
Basic::pend(' ');
}
void win1()
{
win0();
Basic::pend();
cout<<" Please choice these:"<<endl<<endl;;
cout<<" S:设置第一个大数"<<endl<<endl;
cout<<" M:设置第二个大数"<<endl<<endl;
cout<<" D:选择运算"<<endl<<endl;
cout<<" I:查看说明"<<endl<<endl;
cout<<" Q:退出程序"<<endl<<endl;
cout<<" ";
}
//设置第一个大数
void S()
{
char printin[100];
system("cls");
cout<<endl<<endl;
Basic::make_an_char("set Bignum",'-',0,2,11);
Basic::pend(2);
cout<<" --------------------------------------"<<endl<<endl;
cout<<" 请输入第一个大数的值:"<<endl<<endl<<" ";
cin>>printin;
touch1 = Bignum(printin);
cout<<endl<<" 数据存储完成"<<endl;
Basic::pend(2);
cout<<" ";
system("PAUSE");
}
//设置第二个大数
void M()
{
char printin[100];
system("cls");
cout<<endl<<endl;
Basic::make_an_char("set Bignum",'-',0,2,11);
Basic::pend(2);
cout<<" --------------------------------------"<<endl<<endl;
cout<<" 请输入第二个大数的值:"<<endl<<endl<<" ";
cin>>printin;
touch2 = Bignum(printin);
cout<<endl<<" 数据存储完成"<<endl;
Basic::pend(2);
cout<<" ";
system("PAUSE");
}
//选择运算
void D()
{
system("cls");
Basic::make_an_char("选择运算",'-',0,2,9);
char x='0';
Bignum touch3;
cout<<" --------------------------------"<<endl;
cout<<" 请输入运算符:"<<endl;
while(x!='+'&&x!='-'&&x!='*'&&x!='/'&&x!='%')
{
cout<<" ";
cin>>x;
}
cout<<endl<<" ********************************"<<endl<<endl;
cout<<" "<<touch1<<endl;
cout<<" "<<x<<endl;
cout<<" "<<touch2<<endl;
cout<<" ="<<endl;
switch(x)
{
case '+':touch3=touch1+touch2;break;
case '-':touch3=touch1-touch2;break;
case '*':Bignum::multiplication(touch1,touch2);break;
case '/':touch3=touch1/touch2;break;
case '%':touch3=touch1%touch2;break;
default:break;
}
cout<<" "<<touch3<<endl<<endl<<" ********************************"<<endl;
cout<<endl;
system("PAUSE");
}
//查看说明
void I()
{
system("cls");
Basic::pend(2);
Basic::make_an_char("Instruction",'*',1,2,2);
cout<<endl<<endl;
cout<<" Maker: Master"<<endl<<endl;
cout<<" Name: Bignum's Program"<<endl<<endl;
cout<<" Date: 2018.7.19"<<endl<<endl;
cout<<" Version: 1.023"<<endl<<endl;
cout<<" ";
system("PAUSE");
}
//退出程序
void Q()
{
system("cls");
Basic::pend(2);
Basic::make_an_char("Welcome to the next time !",'*',1,2,2);
cout<<endl<<endl<<" ";
}
int main()
{
Bignum tar[20];
char x='c';
while(x!='q'&&x!='Q')
{
win1();
cin>>x;
getchar();
switch(x)
{
case 's':
case 'S':S();break;
case 'm':
case 'M':M();break;
case 'd':
case 'D':D();break;
case 'i':
case 'I':I();break;
case 'q':
case 'Q':Q();break;
default:break;
}
}
return 0;
}
//=============================》如下为 Basic.h 文件
#include<iostream>
using namespace std;
#include<string>
class Basic
{
public:
//====================<输入输出>=======================//
/*
/-----------<pend函数>
/-#
/----(1)默认输出"\n",可直接输入int类型变量或常量给形参n,得到输出n次的换行(默认输出一次)
/----(2)可指定字符p,输入n次(默认输出一次)
/----(3)可连续输出对间隔输出
*/
static void pend(const int n=1)
{
for(int i=0;i<n;i++)
cout<<endl;
}
static void pend(const char p,const int n=1)
{
for(int i=0;i<n;i++)
cout<<p;
}
static void pend(const char p,const char q,const int n=1,const int m=1,const bool s=true)
{
if(s)
{
Basic::pend(p,n);
Basic::pend(q,m);
}
else
{
if(m==n)
for(int i=0;i<n;i++)
{
Basic::pend(p);
Basic::pend(q);
}
}
}
static void pend(const char o,const char p,const char q,const int l=1,const int m=1,const int n=1)
{
Basic::pend(o,l);
Basic::pend(p,m);
Basic::pend(q,n);
}
/*
/-----------<printarray函数>
/-#
/----(1)用于打印一维数组或二维数组
/----(2)可确定初始位置(begin)
/----(3)可设定列间距(lie)
/----(4)使用时必须设定数组长度
/----(5)数据中从du开始读,并结束于 n(即 n可以小于 p的实际长度)
/----(6)数据的列从da开始读,并结束于 m(同上)
*/
template <typename T>
static void printarray(T *p,int n=0,const int lie=1,const int begin=1,int du=0)
{
if(n==0)
return;
Basic::pend(' ',begin);
for(int i=du;i<n;i++)
{
cout<<p[i];
if(i!=n-1)
Basic::pend(' ',lie);
}
Basic::pend();
}
template <typename T>
static void printarray(T **q,int n=0,int m=0,const int hang=0,const int lie=1,const int begin=1,int du=0,int da=0)
{
if(n==0||m==0)
return;
for(int t=da;t<m;t++)
{
Basic::pend(' ',begin);
for(int i=du;i<n;i++)
{
cout<<q[t][i];
if(i!=n-1)
Basic::pend(' ',lie);
}
Basic::pend(hang+1);
}
}
//====================<窗口>=======================//
/*
/-----------<make_an_char函数>
/-#
/----(1)窗口制定
/----(2)可设定长宽
/----(3)可确定初始位置
*/
static void make_an_char(char *q,const char p='*',const int hang=0,const int lie=1,const int begin=1)
{
//最初行
Basic::pend(' ',begin);
Basic::pend(p,lie+1);
for(int i=0;*(q+i)!='\0';i++)
Basic::pend(p);
Basic::pend(p,lie+1);
//最初行
//-------------------------
//hang的行
Basic::pend();
Basic::pend(' ',begin);
for(int j=0;j<hang;j++)
{
Basic::pend(p);
Basic::pend(' ',2*lie);
for(int i=0;*(q+i)!='\0';i++)
Basic::pend(' ');
Basic::pend(p);
Basic::pend();
Basic::pend(' ',begin);
}
//hang的行
//----------------------
//内容行
Basic::pend(p);
Basic::pend(' ',lie);
printf("%s",q);
Basic::pend(' ',lie);
Basic::pend(p);
//内容行
//------------------------
//hang的行
Basic::pend();
Basic::pend(' ',begin);
for(int j=0;j<hang;j++)
{
Basic::pend(p);
Basic::pend(' ',2*lie);
for(int i=0;*(q+i)!='\0';i++)
Basic::pend(' ');
Basic::pend(p);
Basic::pend();
Basic::pend(' ',begin);
}
//hang的行
//---------------------
//最末行
Basic::pend(p,lie+1);
for(int i=0;*(q+i)!='\0';i++)
Basic::pend(p);
Basic::pend(p,lie+1);
//最末行
Basic::pend();
}
};
//=============================》如下为 BIgnum.h 文件
#pragma once
#include<iostream>
#include<string>
using namespace std;
//----<<大数类>>----//
class Bignum
{
protected:
//--------------<内部数据存储>--------------//
//---
//数据存储
char num[100];
//正负存储
bool ifhavef;
public:
//--------------<附加小函数>--------------//
//---
//数据类型转换[直接使用]
//===int和char表示变换
friend int change(char x);
friend char change(int x);
//===int和char*的转换
friend int change_s(char x[100]);
friend void change_s(int x,char y[100]);
//===int和Bignum的类型转换
friend int change_ib(Bignum &x);
friend Bignum change_ib(int x);
//===char转为char[100]
friend void change(char x,char y[100]);
//===char和Bignum的类型转换
friend char change_cb(Bignum &x);
friend Bignum change_cb(char x);
//===char*和Bignum的类型转换
friend void change_cbs(Bignum &x,char y[100]);
friend Bignum change_cbs(char x[100]);
//---
//---
//排除-0的情况(将-0转为+0)
void test();
//排除内部 num 有‘ - ’字符
void test_s();
//读取第first个到第last个成员组成新的字符串 [直接使用]
friend void strf(char n[100],char ios[100],int first,int last);
//---
//--------------<静态小函数>--------------//
//---
//位数函数
//===[长度前移更新 ]
void static runformer(char x[100]);
//===[字符串位数升高 [后面补 0 ](默认升高 1 位) ]
void static run0(char x[100]);
void static run0(char x[100],int ct);
//===[长度后移 x位(默认后移 1 位)]
void static runlatter(char x[100]);
void static runlatter(char x[100],int t);
//---
//---
//相反数
Bignum static anti(Bignum &x);
//交换函数
void static exchange(Bignum &x,Bignum &y);
//返回 10 的 i 次幂
Bignum static run1(const int i);
//---
//---
//长度函数
//===[测量整形、大数或字符串的长度]
int static litude(int x);
int static litude(char x[100]);
int static litude(Bignum &z);
//===[判断是否 x和 y相同长度 ]
bool static ifsamelong(Bignum &x,Bignum &y);
//---
//--------------<output、intput函数>--------------//
//---
//set函数
//===[设置ifhavef]
void setf(const bool ifhavef_s);
//===[设置num]
void setnum(const char num_s[100]);
void setnum(const char x);
//===[设置num和ifhavef]
void set(const char num_s[100],const bool ifhavef_s);
void set(const bool ifhavef_s,const char num_s[100]);
//---
//---
//input函数
void input();
void static input(Bignum &x);
//output函数
void output();
void static output(Bignum &x);
//---
//--------------<运算函数>--------------//
//---
//加法
//===[int置前]
Bignum static addition(int x,int y);
Bignum static addition(int x,char y);
Bignum static addition(int x,char y[100]);
Bignum static addition(int x,Bignum &y);
//===[char置前]
Bignum static addition(char x,int y);
Bignum static addition(char x,char y);
Bignum static addition(char x,char y[100]);
Bignum static addition(char x,Bignum &y);
//===[char*置前]
Bignum static addition(char x[100],int y);
Bignum static addition(char x[100],char y);
Bignum static addition(char x[100],char y[100]);
Bignum static addition(char x[100],Bignum &y);
//===[Bignum置前]
Bignum static addition(Bignum &x,int y);
Bignum static addition(Bignum &x,char y);
Bignum static addition(Bignum &x,char y[100]);
Bignum static addition(Bignum &x,Bignum &y);
//---
//---
//减法
//===[int置前]
Bignum static subtraction(int x,int y);
Bignum static subtraction(int x,char y);
Bignum static subtraction(int x,char y[100]);
Bignum static subtraction(int x,Bignum &y);
//===[char置前]
Bignum static subtraction(char x,int y);
Bignum static subtraction(char x,char y);
Bignum static subtraction(char x,char y[100]);
Bignum static subtraction(char x,Bignum &y);
//===[char*置前]
Bignum static subtraction(char x[100],int y);
Bignum static subtraction(char x[100],char y);
Bignum static subtraction(char x[100],char y[100]);
Bignum static subtraction(char x[100],Bignum &y);
//===[Bignum置前]
Bignum static subtraction(Bignum &x,int y);
Bignum static subtraction(Bignum &x,char y);
Bignum static subtraction(Bignum &x,char y[100]);
Bignum static subtraction(Bignum &x,Bignum &y);
//---
//---
//乘法
//===[int置前]
Bignum static multiplication(int x,int y);//未写
Bignum static multiplication(int x,char y);//未写
Bignum static multiplication(int x,char y[100]);//未写
Bignum static multiplication(int x,Bignum &y);
//===[char置前]
Bignum static multiplication(char x,int y);//未写
Bignum static multiplication(char x,char y);//未写
Bignum static multiplication(char x,char y[100]);//未写
Bignum static multiplication(char x,Bignum &y);
//===[char*置前]
Bignum static multiplication(char x[100],int y);//未写
Bignum static multiplication(char x[100],char y);//未写
Bignum static multiplication(char x[100],char y[100]);//未写
Bignum static multiplication(char x[100],Bignum y);//未写
//===[Bignum置前]
Bignum static multiplication(Bignum &x,int y);
Bignum static multiplication(Bignum &x,char y);
Bignum static multiplication(Bignum &x,char y[100]);
Bignum static multiplication(Bignum &x,Bignum &y);
//---
//---
//除法
//===[char*置前]
Bignum static division(char x[100],int y);
Bignum static division(char x[100],char y);
Bignum static division(char x[100],char y[100]);
Bignum static division(char x[100],Bignum &y);
//===[Bignum置前]
Bignum static division(Bignum &x,int y);
Bignum static division(Bignum &x,char y);
Bignum static division(Bignum &x,char y[100]);
Bignum static division(Bignum &x,Bignum &y);
//---
//---
//求余数
//===[char*置前]
Bignum static rest(char x[100],int y);
Bignum static rest(char x[100],char y);
Bignum static rest(char x[100],char y[100]);
Bignum static rest(char x[100],Bignum &y);
//===[Bignum置前]
Bignum static rest(Bignum &x,Bignum &y);
Bignum static rest(Bignum &x,int y);
Bignum static rest(Bignum &x,char y);
Bignum static rest(Bignum &x,char y[100]);
//---
//---
//求幂数
//===[int置前]
Bignum static pxp(int x,int y);
Bignum static pxp(int x,char y);
Bignum static pxp(int x,char y[100]);
Bignum static pxp(int x,Bignum &y);
//===[char置前]
Bignum static pxp(char x,int y);
Bignum static pxp(char x,char y);
Bignum static pxp(char x,char y[100]);
Bignum static pxp(char x,Bignum &y);
//===[char[100]置前]
Bignum static pxp(char x[100],int y);
Bignum static pxp(char x[100],char y);
Bignum static pxp(char x[100],char y[100]);
Bignum static pxp(char x[100],Bignum &y);
//===[Bignum置前]
Bignum static pxp(Bignum &x,int y);
Bignum static pxp(Bignum &x,char y);
Bignum static pxp(Bignum &x,char y[100]);
Bignum static pxp(Bignum &x,Bignum &y);
//---
//--------------<运算符重载>--------------//
//---
//加法
//===[Bignum置前]
friend Bignum operator +(Bignum &x,int y);
friend Bignum operator +(Bignum &x,char y);
friend Bignum operator +(Bignum &x,char y[100]);
friend Bignum operator +(Bignum &x,Bignum &y);
//===[Bignum置后]
friend Bignum operator +(int x,Bignum &y);
friend Bignum operator +(char x,Bignum &y);
friend Bignum operator +(char x[100],Bignum &y);
//---
//---
//减法
//===[Bignum置前]
friend Bignum operator -(Bignum &x,int y);
friend Bignum operator -(Bignum &x,char y);
friend Bignum operator -(Bignum &x,char y[100]);
friend Bignum operator -(Bignum &x,Bignum &y);
//===[Bignum置后]
friend Bignum operator -(int x,Bignum &y);
friend Bignum operator -(char x,Bignum &y);
friend Bignum operator -(char x[100],Bignum &y);
//---
//---
//除法
//===[Bignum置前]
friend Bignum operator /(Bignum &x,int y);
friend Bignum operator /(Bignum &x,char y);
friend Bignum operator /(Bignum &x,char y[100]);
friend Bignum operator /(Bignum &x,Bignum &y);
//===[Bignum置后]
friend Bignum operator /(char x[100],Bignum &y);
//---
//---
//求余数
//===[Bignum置前]
friend Bignum operator %(Bignum &x,int y);
friend Bignum operator %(Bignum &x,char y);
friend Bignum operator %(Bignum &x,char y[100]);
friend Bignum operator %(Bignum &x,Bignum &y);
//===[Bignum置后]
friend Bignum operator %(char x[100],Bignum &y);
//---
//---
//单目运算符
//===[++运算]
//---
//======[前置++](绝对值)
Bignum operator ++();
//---
//======[后置++](数值运算)
Bignum operator ++(int x);
//===[--运算]
//---
//======[前置--](相反数)
Bignum operator --();
//---
//======[后置--](数值运算)
Bignum operator --(int x);
//---
//---
//比较函数
//===[小于]
//---
//======[Bignum置前]
friend bool operator <(Bignum &x,int y);
friend bool operator <(Bignum &x,char y);
friend bool operator <(Bignum &x,char y[100]);
friend bool operator <(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator <(int x,Bignum &y);
friend bool operator <(char x,Bignum &y);
friend bool operator <(char x[100],Bignum &y);
//---
//===[大于]
//---
//======[Bignum置前]
friend bool operator >(Bignum &x,int y);
friend bool operator >(Bignum &x,char y);
friend bool operator >(Bignum &x,char y[100]);
friend bool operator >(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator >(int x,Bignum &y);
friend bool operator >(char x,Bignum &y);
friend bool operator >(char x[100],Bignum &y);
//---
//===[等于]
//---
//======[Bignum置前]
friend bool operator ==(Bignum &x,int y);
friend bool operator ==(Bignum &x,char y);
friend bool operator ==(Bignum &x,char y[100]);
friend bool operator ==(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator ==(int x,Bignum &y);
friend bool operator ==(char x,Bignum &y);
friend bool operator ==(char x[100],Bignum &y);
//---
//===[不等于]
//---
//======[Bignum置前]
friend bool operator !=(Bignum &x,int y);
friend bool operator !=(Bignum &x,char y);
friend bool operator !=(Bignum &x,char y[100]);
friend bool operator !=(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator !=(int x,Bignum &y);
friend bool operator !=(char x,Bignum &y);
friend bool operator !=(char x[100],Bignum &y);
//---
//===[小于或等于]
//---
//======[Bignum置前]
friend bool operator <=(Bignum &x,int y);
friend bool operator <=(Bignum &x,char y);
friend bool operator <=(Bignum &x,char y[100]);
friend bool operator <=(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator <=(int x,Bignum &y);
friend bool operator <=(char x,Bignum &y);
friend bool operator <=(char x[100],Bignum &y);
//---
//===[大于或等于]
//---
//======[Bignum置前]
friend bool operator >=(Bignum &x,int y);
friend bool operator >=(Bignum &x,char y);
friend bool operator >=(Bignum &x,char y[100]);
friend bool operator >=(Bignum &x,Bignum &y);
//======[Bignum置后]
friend bool operator >=(int x,Bignum &y);
friend bool operator >=(char x,Bignum &y);
friend bool operator >=(char x[100],Bignum &y);
//---
//---
//输入输出流
//===[输入]
friend istream & operator >>(istream &in,Bignum &x);
//===[输出]
friend ostream & operator <<(ostream &out,Bignum &x);
//---
//--------------<构造和析构函数>--------------//
//---
//构造函数
//===无参构造函数
Bignum();
//===转换构造函数
Bignum(int num);
Bignum(char p);
Bignum(char p[100]);
//===拷贝构造函数
Bignum(Bignum &x);
//---
//---
//析构函数
~Bignum();
};
//========================================》如下为 Bignum.cpp 文件
//--------------<附加小函数>--------------//
//---
//数据类型转换[直接使用]
//===int和char表示变换
int change(char x)
{
return (int)(x-'0');
}
char change(int x)
{
return (char)(x+'0');
}
//===int和char*的转换
int change_s(char x[100])
{
int z=0,k=1;
bool havef=x[0]=='-';
char y[100];
strcpy(y,x);
if(havef)
{
y[0]='0';
Bignum::runformer(y);
}
int l=Bignum::litude(y);
for(int i=l-1;i>=0;i--)
{
z=z+k*change(y[i]);
k=k*10;
}
if(havef)
z=-z;
return z;
}
void change_s(int x,char y[100])
{
bool havef=x<0;
if(havef)
x=-x;
char p[100]="0";
int l=Bignum::litude(x);
int u=1;
for(int i=1;i<l;i++)
u=u*10;
for(int i=0;i<l;i++)
{
p[i]=change((x/u)%10);
u=u/10;
}
p[l]='\0';
Bignum::runformer(p);
if(havef)
{
Bignum::runlatter(p);
p[0]='-';
}
strcpy(y,p);
}
//===int和Bignum的类型转换
int change_ib(Bignum &x)
{
return x.ifhavef?-change_s(x.num):change_s(x.num);
}
Bignum change_ib(int x)
{
Bignum z;
bool havef=x<0;
if(havef)
x=-x;
char p[100];
change_s(x,p);
z.set(p,havef);
return z;
}
//===char*转为char[100]
void change(char x,char y[100])
{
y[0]=x;
y[1]='\0';
}
//===char和Bignum的类型转换
char change_cb(Bignum &x)
{
x.test();
return x.num[0];
}
Bignum change_cb(char x)
{
Bignum y(x);
return y;
}
//===char*和Bignum的类型转换
void change_cbs(Bignum &x,char y[100])
{
Bignum::runformer(x.num);
x.test();
strcpy(y,x.num);
if(x.ifhavef)
{
Bignum::runlatter(y);
y[0]='-';
}
}
Bignum change_cbs(char x[100])
{
Bignum z(x);
return z;
}
//---
//---
//排除-0的情况(将-0转为+0)
void Bignum::test()
{
if(ifhavef&&strcmp(num,"0")==0)
ifhavef=false;
}
//排除内部 num 有‘ - ’字符
void Bignum::test_s()
{
if(num[0]=='-')
{
num[0]='0';
Bignum::runformer(num);
ifhavef=!ifhavef;
}
}
//读取第first个到第last个成员组成新的字符串 [直接使用]
void strf(char pr[100],char save[100],int first,int last)
{
int i,j;
for(i=0,j=first-1;j!=last&&pr[j]!='\0';j++,i++)
save[i]=pr[j];
save[i]='\0';
}
//---
//--------------<静态小函数>--------------//
//---
//位数函数
//===[长度前移更新 ]
void Bignum::runformer(char x[100])
{
int m=0;//执行前移的次数
for(int i=0;i<100;i++)//测定m的值
{
if(x[i]!='0')
break;
m++;
}
if(m==0)
return ;
for(int i=0;x[i+m-1]!='\0';i++)//前移
x[i]=x[i+m];
if(x[0]=='\0')
{
x[1]=x[0];
x[0]='0';
}
}
//===[字符串位数升高 [后面补 0 ](默认升高 1 位) ]
void Bignum::run0(char x[100])
{
int zz=Bignum::litude(x);
x[zz]='0';
x[zz+1]='\0';
}
void Bignum::run0(char x[100],int ct)
{
for(int i=1;i<=ct;i++)
Bignum::run0(x);
}
//===[长度后移 x位(默认后移 1 位)]
void Bignum::runlatter(char x[100])
{
char s[100];
int i;
for(i=0;i<100&&x[i]!='\0';i++)
s[i+1]=x[i];
s[i+1]='\0';
s[0]='0';
strcpy(x,s);
}
void Bignum::runlatter(char x[100],int t)
{
char s[100];
s[1]=x[0];
int i;
for(i=0;i<100&&x[i]!='\0';i++)//后移一次
{
s[i+1]=x[i];
}
s[i+1]='\0';
s[0]='0';
strcpy(x,s);
if(t!=1)//递归
Bignum::runlatter(x,t-1);
}
//---
//---
//相反数
Bignum Bignum::anti(Bignum &x)
{
Bignum z(x.num);
z.setf(!x.ifhavef);
z.test();
return z;
}
//交换函数
void Bignum::exchange(Bignum &x,Bignum &y)
{
Bignum z(x);
x.set(y.num,y.ifhavef);
y.set(z.num,z.ifhavef);
x.test();
y.test();
}
//返回 10 的 i 次幂
Bignum Bignum::run1(int i)
{
Bignum z;
z.set("1",false);
Bignum::run0(z.num,i);
z.test();//无用
return z;
}
//---
//---
//长度函数
//===[测量整形、大数或字符串的长度]
//------准确的长度(不含'\0')
//------int最大长度为10
int Bignum::litude(int x)
{
int num=10;
int z=1000000000;
if(x==0)
return 1;
while(num-1)
{
if((x/z)!=0)
break;
num--;
z=z/10;
}
return num;
}
int Bignum::litude(char x[100])
{
int m;
Bignum::runformer(x);
for(int i=0;i<100;i++)
if(x[i]=='\0')
{
m=i;
break;
}
return m;
}
int Bignum::litude(Bignum &x)
{
return Bignum::litude(x.num);
}
//===[判断是否 x和 y相同长度 ]
bool Bignum::ifsamelong(Bignum &x,Bignum &y)
{
return(Bignum::litude(x)==Bignum::litude(y));
}
//---
//--------------<output、intput函数>--------------//
//---
//set函数
//===[设置ifhavef]
void Bignum::setf(const bool ifhavef_s)
{
ifhavef=ifhavef_s;
}
//===[设置num]
void Bignum::setnum(const char x)
{
char arrays[100];
arrays[1]='\0';
arrays[0]=x;
setnum(arrays);
}
void Bignum::setnum(const char num_s[100])
{
strcpy(num,num_s);
}
//===[设置num和ifhavef]
void Bignum::set(const char num_s[100],const bool ifhavef_s)
{
setf(ifhavef_s);
setnum(num_s);
test();
}
void Bignum::set(const bool ifhavef_s,const char num_s[100])
{
set(num_s,ifhavef_s);
}
//---
//---
//input函数
void Bignum::input()
{
char x[100];
cin>>x;
if(x[0]=='-')
{
x[0]='0';
Bignum::runformer(x);
}
strcpy(num,x);
}
void Bignum::input(Bignum &x)
{
x.input();
}
//output函数
void Bignum::output()
{
cout<<*this;
}
void Bignum::output(Bignum &x)
{
x.output();
}
//---
//--------------<运算函数>--------------//
//---
//加法
//===[int置前]
Bignum Bignum::addition(int x,int y)
{
return change_ib(x+y);
}
Bignum Bignum::addition(int x,char y)
{
return change_ib(x+change(y));
}
Bignum Bignum::addition(int x,char y[100])
{
Bignum z1(y);
Bignum z2(x);
return z1+z2;
}
Bignum Bignum::addition(int x,Bignum &y)
{
return x+y;
}
//===[char置前]
Bignum Bignum::addition(char x,int y)
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(char x,char y)
{
Bignum z(change(x)+change(y));
return z;
}
Bignum Bignum::addition(char x,char y[100])
{
Bignum z(y);
return z+x;
}
Bignum Bignum::addition(char x,Bignum &y)
{
Bignum z(x);
return x+y;
}
//===[char*置前]
Bignum Bignum::addition(char x[100],int y)
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(char x[100],char y)
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(char x[100],char y[100])
{
Bignum t(x);
return t+y;
}
Bignum Bignum::addition(char x[100],Bignum &y)
{
return x+y;
}
//===[Bignum置前]
Bignum Bignum::addition(Bignum &x,int y)
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(Bignum &x,char y)
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(Bignum &x,char y[100])
{
return Bignum::addition(y,x);
}
Bignum Bignum::addition(Bignum &x,Bignum &y)
{
Bignum z=x+y;
return z;
}
//---
//---
//减法
//===[int置前]
Bignum Bignum::subtraction(int x,int y)
{
Bignum z(x-y);
return z;
}
Bignum Bignum::subtraction(int x,char y)
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(int x,char y[100])
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(int x,Bignum &y)
{
return x-y;
}
//===[char置前]
Bignum Bignum::subtraction(char x,int y)
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x,char y)
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x,char y[100])
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x,Bignum &y)
{
return x-y;
}
//===[char*置前]
Bignum Bignum::subtraction(char x[100],int y)
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x[100],char y)
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x[100],char y[100])
{
Bignum t1(x),t2(y);
return t1-t2;
}
Bignum Bignum::subtraction(char x[100],Bignum &y)
{
return x-y;
}
//===[Bignum置前]
Bignum Bignum::subtraction(Bignum &x,int y)
{
return x-y;
}
Bignum Bignum::subtraction(Bignum &x,char y)
{
return x-y;
}
Bignum Bignum::subtraction(Bignum &x,char y[100])
{
return x-y;
}
Bignum Bignum::subtraction(Bignum &x,Bignum &y)
{
return x-y;
}
//---
//---
//乘法
//===[int置前]
Bignum Bignum::multiplication(int x,int y)
{
return change_ib(x*y);
}
Bignum Bignum::multiplication(int x,char y)
{
return change_ib(x*change(y));
}
Bignum Bignum::multiplication(int x,char y[100])
{
return Bignum::subtraction(x,change_cbs(y));
}
Bignum Bignum::multiplication(int x,Bignum &y)
{
Bignum z;
z=Bignum::multiplication(y,x);
return z;
}
//===[char置前]
Bignum Bignum::multiplication(char x,int y)
{
return Bignum::multiplication(y,x);
}
Bignum Bignum::multiplication(char x,char y)
{
Bignum Bignum::multiplication(char x,char y[100])
{
return Bignum::multiplication(x,change_cbs(y));
}
Bignum Bignum::multiplication(char x,Bignum &y)
{
Bignum z;
z=Bignum::multiplication(y,change(x));
return z;
}
//===[char*置前]
Bignum Bignum::multiplication(char x[100],int y)
{
return Bignum::multiplication(y,x);
}
Bignum Bignum::multiplication(char x[100],char y)
{
return Bignum::multiplication(y,x);
}
Bignum Bignum::multiplication(char x[100],char y[100])
{
Bignum t1(x),t2(y);
return Bignum::multiplication(t1,t2);
}
//===[Bignum置前]
Bignum Bignum::multiplication(Bignum &x,int y)
{
Bignum t(x);
if(y>=0&&y<=9)
{
char arrays[100];
Bignum::runlatter(t.num);
arrays[Bignum::litude(t)]='\0';
for(int i=Bignum::litude(t)-1,k=0;i>=0;i--)
{
int answer=k+change(t.num[i])*y;
k=answer/10;
answer=answer%10;
arrays[i]=change(answer);
}
Bignum::runformer(arrays);
Bignum z(arrays);
return z;
}
else
return t;
}
Bignum Bignum::multiplication(Bignum &x,char y)
{
Bignum z;
z=Bignum::multiplication(x,change(y));
return z;
}
Bignum Bignum::multiplication(Bignum &x,char y[100])
{
Bignum z(y);
return Bignum::multiplication(x,z);
}
Bignum Bignum::multiplication(Bignum &x,Bignum &y)
{
Bignum z("0");
if(!x.ifhavef&&!y.ifhavef)
{
Bignum t1(x),t2(y);
int l=Bignum::litude(t2);
for(int t=l-1;t>=0;t--)
{
Bignum t3=Bignum::multiplication(t1,change(t2.num[t]));
Bignum::run0(t1.num);
z=z+t3;
}
Bignum::runformer(z.num);
z.setf(false);
}
else if(x.ifhavef&&y.ifhavef)
z=Bignum::multiplication(Bignum::anti(x),Bignum::anti(y));
else if(x.ifhavef&&!y.ifhavef)
{
z=Bignum::multiplication(Bignum::anti(x),y);
z.setf(true);
}
else
z=Bignum::multiplication(y,x);
z.test();
return z;
}
//---
//---
//除法
//===[char[100]置前]
Bignum Bignum::division(char x[100],int y)
{
Bignum z(x);
return z/y;
}
Bignum Bignum::division(char x[100],char y)
{
Bignum z(x);
return z/y;
}
Bignum Bignum::division(char x[100],char y[100])
{
Bignum z(x);
return z/y;
}
Bignum Bignum::division(char x[100],Bignum &y)
{
return x/y;
}
//===[Bignum置前]
Bignum Bignum::division(Bignum &x,int y)
{
Bignum z("0");
if(!(y>0&&y<=9))
return z;
char arrays[100];
Bignum t(x);
int l=Bignum::litude(x);
arrays[l]='\0';
for(int i=0,k=0;i<l;i++)
{
int answer=k*10+change(x.num[i]);
k=answer%y;
answer=answer/y;
arrays[i]=change(answer);
}
Bignum::runformer(arrays);
z.set(arrays,false);
z.test();
return z;
}
Bignum Bignum::division(Bignum &x,char y)
{
Bignum z(Bignum::division(x,change(y)));
return z;
}
Bignum Bignum::division(Bignum &x,char y[100])
{
return x/y;
}
Bignum Bignum::division(Bignum &x,Bignum &y)
{
Bignum z;
if(!x.ifhavef&&!y.ifhavef)
{
z.setf(false);
Bignum t1(x),t2(y);
Bignum::runformer(t1.num);
Bignum::runformer(t2.num);
int l1,l2;
l1=Bignum::litude(t1);
l2=Bignum::litude(t2);
if(l1<l2||strcmp(t1.num,t2.num)<0)
z.setnum('0');
else if(strcmp(t1.num,t2.num)==0)
z.setnum('1');
else if(l1==l2)
{
char f;
f='2';
while(Bignum::multiplication(t2,f)<t1)
f++;
f--;
z.setnum(f);
}
else
{
z.setnum('0');
for(int i=l1-l2;i>=0;i--)
{
Bignum t3(t2);
Bignum::run0(t3.num,i);
int k=0;
while(t1>t3)
{
t1=t1-t3;
k++;
}
z=z+Bignum::multiplication(k,Bignum::run1(i));
}
}
}
else if(x.ifhavef&&y.ifhavef)
z=Bignum::division(Bignum::anti(x),Bignum::anti(y));
else if(x.ifhavef&&!y.ifhavef)
z=Bignum::anti(Bignum::division(Bignum::anti(x),y));
else
z=Bignum::anti(Bignum::division(x,Bignum::anti(y)));
z.test();
return z;
}
//---
//---
//求余数
//===[char*置前]
Bignum Bignum::rest(char x[100],int y)
{
Bignum z(x);
return z%y;
}
Bignum Bignum::rest(char x[100],char y)
{
Bignum z(x);
return z%y;
}
Bignum Bignum::rest(char x[100],char y[100])
{
Bignum z(x);
return z%y;
}
Bignum Bignum::rest(char x[100],Bignum &y)
{
Bignum z(x);
return z%y;
}
//===[Bignum置前]
Bignum Bignum::rest(Bignum &x,int y)
{
return x%y;
}
Bignum Bignum::rest(Bignum &x,char y)
{
return x%y;
}
Bignum Bignum::rest(Bignum &x,char y[100])
{
return x%y;
}
Bignum Bignum::rest(Bignum &x,Bignum &y)
{
return x%y;
}
//---
//---
//求幂数
//===[int置前]
Bignum Bignum::pxp(int x,int y)
{
return Bignum::pxp(change_ib(x),y);
}
Bignum Bignum::pxp(int x,char y)
{
return Bignum::pxp(change_ib(x),y);
}
Bignum Bignum::pxp(int x,char y[100])
{
return Bignum::pxp(change_ib(x),y);
}
Bignum Bignum::pxp(int x,Bignum &y)
{
return Bignum::pxp(change_ib(x),y);
}
//===[char置前]
Bignum Bignum::pxp(char x,int y)
{
return Bignum::pxp(change_cb(x),y);
}
Bignum Bignum::pxp(char x,char y)
{
return Bignum::pxp(change_cb(x),y);
}
Bignum Bignum::pxp(char x,char y[100])
{
return Bignum::pxp(change_cb(x),y);
}
Bignum Bignum::pxp(char x,Bignum &y)
{
return Bignum::pxp(change_cb(x),y);
}
//===[char[100]置前]
Bignum Bignum::pxp(char x[100],int y)
{
return Bignum::pxp(change_cbs(x),y);
}
Bignum Bignum::pxp(char x[100],char y)
{
return Bignum::pxp(change_cbs(x),y);
}
Bignum Bignum::pxp(char x[100],char y[100])
{
return Bignum::pxp(change_cbs(x),y);
}
Bignum Bignum::pxp(char x[100],Bignum &y)
{
return Bignum::pxp(change_cbs(x),y);
}
//===[Bignum置前]
Bignum Bignum::pxp(Bignum &x,int y)
{
return Bignum::pxp(x,change_ib(y));
}
Bignum Bignum::pxp(Bignum &x,char y)
{
return Bignum::pxp(x,change_cb(y));
}
Bignum Bignum::pxp(Bignum &x,char y[100])
{
return Bignum::pxp(x,change_cbs(y));
}
Bignum Bignum::pxp(Bignum &x,Bignum &y)
{
x.test();x.test_s();
y.test();y.test_s();
Bignum::runformer(x.num);
Bignum::runformer(y.num);
Bignum t1(x),t2(y);
if(!t1.ifhavef)
{
if(t1=='0')
return change_ib(0);
else if(t1=='1')
return change_ib(1);
if(t2=='0')
return change_ib(1);
else if(t2>0)
{
Bignum z(1);
while(t2>0)
{
z=Bignum::multiplication(t1,z);
t2--;
}
return z;
}
else
return change_ib(0);
}
else if(t1.ifhavef)
{
if(t2%2==0)
return Bignum::pxp(Bignum::anti(t1),t2);
else
return Bignum::anti(Bignum::pxp(Bignum::anti(t1),t2));
}
return t1;
}
//---
//--------------<运算符重载>--------------//
//---
//加法
//===[Bignum置前]
Bignum operator +(Bignum &x,int y)
{
return x+change_ib(y);
}
Bignum operator +(Bignum &x,char y)
{
return x+change_cb(y);
}
Bignum operator +(Bignum &x,char y[100])
{
return x+change_cbs(y);
}
Bignum operator +(Bignum &x,Bignum &y)
{
Bignum zz;
if(!x.ifhavef&&!y.ifhavef)
{
Bignum t1(x),t2(y);
int l1,l2;
l1=Bignum::litude(x);
l2=Bignum::litude(y);
//以上-----初步计算
if(l1==l2)
{
Bignum::runlatter(t1.num);
Bignum::runlatter(t2.num);
l1++;
l2++;
}
else if(l1<l2)
{
Bignum::runlatter(t2.num);
Bignum::runlatter(t1.num,l2-l1+1);
l2++;
l1=l2;
}
else if(l1>l2)
{
Bignum::runlatter(t1.num);
Bignum::runlatter(t2.num,l1-l2+1);
l1++;
l2=l1;
}
char arrays[100];
arrays[l1]='\0';
//以上为规划
for(int j=l1-1,k=0;j>=0;j--)
{
int answer=change(t1.num[j])+change(t2.num[j])+k;
k=answer/10;
arrays[j]=change(answer%10);
}
Bignum::runformer(arrays);
zz.setnum(arrays);
}
else if(x.ifhavef&&y.ifhavef)
zz=Bignum::anti(Bignum::anti(x)+Bignum::anti(y));
else if(x.ifhavef&&!y.ifhavef)
zz=y-Bignum::anti(x);
else
Bignum zz=x-Bignum::anti(y);
zz.test();
return zz;
}
//===[Bignum置后]
Bignum operator +(int x,Bignum &y)
{
return y+x;
}
Bignum operator +(char x,Bignum &y)
{
return y+x;
}
Bignum operator +(char x[100],Bignum &y)
{
return y+x;
}
//---
//---
//减法
//===[Bignum置前]
Bignum operator -(Bignum &x,int y)
{
return x-change_ib(y);
}
Bignum operator -(Bignum &x,char y)
{
return x-change_cb(y);
}
Bignum operator -(Bignum &x,char y[100])
{
return x-change_cbs(y);
}
Bignum operator -(Bignum &x,Bignum &y)
{
Bignum result;
if(!x.ifhavef&&!y.ifhavef)
{
char arrays[100];
bool resulthavef=false;
Bignum t1(x),t2(y);
int l1=Bignum::litude(x),l2=Bignum::litude(y);
if(l1==l2)
{
Bignum::runlatter(t1.num);
Bignum::runlatter(t2.num);
l1++;
l2++;
}
else if(l1<l2)
{
Bignum::runlatter(t2.num);
Bignum::runlatter(t1.num,l2-l1+1);
l2++;
l1=l2;
}
else if(l1>l2)
{
Bignum::runlatter(t1.num);
Bignum::runlatter(t2.num,l1-l2+1);
l1++;
l2=l1;
}
//统一排位
Bignum t3(t1),t4(t2);
if(strcmp(t1.num,t2.num)<0)
{
Bignum::exchange(t3,t4);
result.ifhavef=true;
}
if(strcmp(t1.num,t2.num)==0)
{
arrays[0]='0';
arrays[1]='\0';
}
else
{
arrays[l2]='\0';
for(int j=l2-1,k=0;j>=0;j--)
{
int answer=change(t3.num[j])-change(t4.num[j])-k;
if(answer<0)
{
k=1;
answer=answer+10;
}
else
k=0;
arrays[j]=change(answer);
}
}
Bignum::runformer(arrays);
result.setnum(arrays);
result.setf(resulthavef);
}
else if(x.ifhavef&&y.ifhavef)
result=Bignum::anti(y)-Bignum::anti(x);
else if(x.ifhavef&&!y.ifhavef)
result=Bignum::anti(Bignum::anti(x)+y);
else
result=Bignum::anti(y)+x;
result.test();
return result;
}
//===[Bignum置后]
Bignum operator -(int x,Bignum &y)
{
return y-x;
}
Bignum operator -(char x,Bignum &y)
{
return y-x;
}
Bignum operator -(char x[100],Bignum &y)
{
return y-x;
}
//---
//---
//除法
//===[Bignum置前]
Bignum operator /(Bignum &x,int y)
{
return x/change_ib(y);
}
Bignum operator /(Bignum &x,char y)
{
return x/change_cb(y);
}
Bignum operator /(Bignum &x,char y[100])
{
return x/change_cbs(y);
}
Bignum operator /(Bignum &x,Bignum &y)
{
Bignum z=Bignum::division(x,y);
return z;
}
//===[Bignum置后]
Bignum operator /(char x[100],Bignum &y)
{
return change_cbs(x)/y;
}
//---
//---
//求余数
//===[Bignum置前]
Bignum operator %(Bignum &x,int y)
{
return x%change_ib(y);
}
Bignum operator %(Bignum &x,char y)
{
return x%change_cb(y);
}
Bignum operator %(Bignum &x,char y[100])
{
return x%change_cbs(y);
}
Bignum operator %(Bignum &x,Bignum &y)
{
Bignum answer;
answer.setf(false);
Bignum t1(x),t2(y);
if(t2.ifhavef||strcmp(t2.num,"0")==0)//除数不是正数
{
answer.setnum("0");
return answer;
}
int l1,l2;
Bignum::runformer(t1.num);
Bignum::runformer(t2.num);
l1=Bignum::litude(t1);
l2=Bignum::litude(t2);
if(!t1.ifhavef)
{
if(t1==t2)
answer.setnum("0");
else if(t1>t2)
{
if(l1==l2||l1==l2+1)
{
for(int i=1;i>=0;i--)
{
Bignum t3(t2);
Bignum::run0(t3.num,i);
while(t1>t3)
t1=t1-t3;
}
answer.setnum(t1.num);
}
else
{
int i;
for(i=l1-l2;i>=0;i--)
{
Bignum t3(t2);
Bignum::run0(t3.num,i);
while(t1>t3)
t1=t1-t3;
}
answer.setnum(t1.num);
}
}
else
answer=t2;
}
else if(t1.ifhavef)
{
if(Bignum::anti(t1)==t2)
answer.setnum("0");
else if(Bignum::anti(t1)>t2)
answer=t2-(Bignum::anti(t1)%t2);
else
answer=t1+t2;
}
answer.test();
return answer;
}
//===[Bignum置后]
Bignum operator %(char x[100],Bignum &y)
{
return change_cbs(x)%y;
}
//---
//---
//单目运算符
//===[++运算]
//---
//======[前置++](绝对值)
Bignum Bignum::operator ++()
{
test();
Bignum::runformer(this->num);
ifhavef=false;
return *this;
}
//---
//======[后置++](数值运算)
Bignum Bignum::operator ++(int x)
{
test();
Bignum::runformer(this->num);
*this=*this+1;
return *this;
}
//===[--运算]
//---
//======[前置--](相反数)
Bignum Bignum::operator --()
{
test();
Bignum::runformer(this->num);
ifhavef=!ifhavef;
return *this;
}
//---
//======[后置--](数值运算)
Bignum Bignum::operator --(int x)
{
test();
Bignum::runformer(this->num);
*this=*this-1;
return *this;
}
//---
//---
//比较函数
//===[小于]
//---
//======[Bignum置前]
bool operator <(Bignum &x,int y)
{
return change_ib(y)<x;
}
bool operator <(Bignum &x,char y)
{
return change_cb(y)<x;
}
bool operator <(Bignum &x,char y[100])
{
return change_cbs(y)<x;
}
bool operator <(Bignum &x,Bignum &y)
{
x.test();
Bignum::runformer(x.num);
y.test();
Bignum::runformer(y.num);
int l1,l2;
l1=Bignum::litude(x);
l2=Bignum::litude(y);
bool it=false;
if(x.ifhavef&&y.ifhavef)
{
if(l1==l2)
it=strcmp(x.num,y.num)>0;
else if(l1>l2)
it=!it;
}
else if(!x.ifhavef&&!y.ifhavef)
{
if(l1==l2)
it=strcmp(x.num,y.num)<0;
else if(l2>l1)
it=!it;
}
else if(!x.ifhavef&&y.ifhavef)
it=!it;
return it;
}
//======[Bignum置后]
bool operator <(int x,Bignum &y)
{
return change_ib(x)<y;
}
bool operator <(char x,Bignum &y)
{
return change_cb(x)<y;
}
bool operator <(char x[100],Bignum &y)
{
return change_cbs(x)<y;
}
//---
//===[大于]
//---
//======[Bignum置前]
bool operator >(Bignum &x,int y)
{
return change_ib(y)>x;
}
bool operator >(Bignum &x,char y)
{
return change_cb(y)>x;
}
bool operator >(Bignum &x,char y[100])
{
return change_cbs(y)>x;
}
bool operator >(Bignum &x,Bignum &y)
{
return y<x;
}
//======[Bignum置后]
bool operator >(int x,Bignum &y)
{
return change_ib(x)>y;
}
bool operator >(char x,Bignum &y)
{
return change_cb(x)>y;
}
bool operator >(char x[100],Bignum &y)
{
return change_cbs(x)>y;
}
//---
//===[等于]
//---
//======[Bignum置前]
bool operator ==(Bignum &x,int y)
{
return change_ib(y)==x;
}
bool operator ==(Bignum &x,char y)
{
return change_cb(y)==x;
}
bool operator ==(Bignum &x,char y[100])
{
return change_cbs(y)==x;
}
bool operator ==(Bignum &x,Bignum &y)
{
return strcmp(x.num,y.num)!=0&&Bignum::ifsamelong(x,y);
}
//======[Bignum置后]
bool operator ==(int x,Bignum &y)
{
return change_ib(x)==y;
}
bool operator ==(char x,Bignum &y)
{
return change_cb(x)==y;
}
bool operator ==(char x[100],Bignum &y)
{
return change_cbs(x)==y;
}
//---
//===[不等于]
//---
//======[Bignum置前]
bool operator !=(Bignum &x,int y)
{
return change_ib(y)!=x;
}
bool operator !=(Bignum &x,char y)
{
return change_cb(y)!=x;
}
bool operator !=(Bignum &x,char y[100])
{
return change_cbs(y)!=x;
}
bool operator !=(Bignum &x,Bignum &y)
{
return !(x==y);
}
//======[Bignum置后]
bool operator !=(int x,Bignum &y)
{
return change_ib(x)!=y;
}
bool operator !=(char x,Bignum &y)
{
return change_cb(x)!=y;
}
bool operator !=(char x[100],Bignum &y)
{
return change_cbs(x)!=y;
}
//---
//===[小于或等于]
//---
//======[Bignum置前]
bool operator <=(Bignum &x,int y)
{
return change_ib(y)<=x;
}
bool operator <=(Bignum &x,char y)
{
return change_cb(y)<=x;
}
bool operator <=(Bignum &x,char y[100])
{
return change_cbs(y)<=x;
}
bool operator <=(Bignum &x,Bignum &y)
{
return (x<y)||(x==y);
}
//======[Bignum置后]
bool operator <=(int x,Bignum &y)
{
return change_ib(x)<=y;
}
bool operator <=(char x,Bignum &y)
{
return change_cb(x)<=y;
}
bool operator <=(char x[100],Bignum &y)
{
return change_cbs(x)<=y;
}
//---
//===[大于或等于]
//---
//======[Bignum置前]
bool operator >=(Bignum &x,int y)
{
return change_ib(y)>=x;
}
bool operator >=(Bignum &x,char y)
{
return change_cb(y)>=x;
}
bool operator >=(Bignum &x,char y[100])
{
return change_cbs(y)>=x;
}
bool operator >=(Bignum &x,Bignum &y)
{
return (y<x)||(x==y);
}
//======[Bignum置后]
bool operator >=(int x,Bignum &y)
{
return change_ib(x)>=y;
}
bool operator >=(char x,Bignum &y)
{
return change_cb(x)>=y;
}
bool operator >=(char x[100],Bignum &y)
{
return change_cbs(x)>=y;
}
//---
//---
//输入输出流
//===[输入]
istream & operator >>(istream &in,Bignum &x)
{
char str[100];
in>>str;
x.setf(false);
if(str[0]=='-')
{
str[0]='0';
x.setf(true);
Bignum::runformer(str);
}
x.setnum(str);
x.test();
return in;
}
//===[输出]
ostream & operator <<(ostream &out,Bignum &x)
{
x.test();
if(x.ifhavef)
out<<'-';
out<<x.num;
return out;
}
//---
//--------------<构造和析构函数>--------------//
//---
//构造函数
//===无参构造函数
Bignum::Bignum()
{
ifhavef=false;
num[0]='1';
num[1]='0';
num[2]='0';
num[3]='\0';
}
//===转换构造函数
Bignum::Bignum(int x)
{
Bignum(change_ib(x));
}
Bignum::Bignum(char p)
{
ifhavef=false;
num[0]=p;
num[1]='\0';
}
Bignum::Bignum(char p[100])
{
ifhavef=false;
if(p[0]!='-')
strcpy(num,p);
else
{
char temp[100];
for(int i=0;i<99;i++)
temp[i]=p[i+1];
temp[99]='\0';
strcpy(num,temp);
ifhavef=true;
}
test();
}
//===拷贝构造函数
Bignum::Bignum(Bignum &x)
{
ifhavef=x.ifhavef;
strcpy(num,x.num);
}
//---
//---
//析构函数
Bignum::~Bignum()
{
}
BIgnum类的程序提交的更多相关文章
- 怎样通过Java程序提交yarn的mapreduce计算任务
因为项目需求,须要通过Java程序提交Yarn的MapReduce的计算任务.与一般的通过Jar包提交MapReduce任务不同,通过程序提交MapReduce任务须要有点小变动.详见下面代码. 下面 ...
- Spark集群模式&Spark程序提交
Spark集群模式&Spark程序提交 1. 集群管理器 Spark当前支持三种集群管理方式 Standalone-Spark自带的一种集群管理方式,易于构建集群. Apache Mesos- ...
- 微信小程序提交审核并发布详细流程
微信小程序提交审核并发布详细流程 审核在1小时到N天不等 官方7天,一般3天内 提交审核?如何发布?审核过程中注意事项? 服务器: 域名只支持 https (request.uploadFile.do ...
- 使用System.Timers.Timer类实现程序定时执行
使用System.Timers.Timer类实现程序定时执行 在C#里关于定时器类有3个:System.Windows.Forms.Timer类.System.Threading.Timer类和Sys ...
- 用Stopwatch类获得程序运行时间
我们可以用Stopwatch类获得程序的运行时间,在优化代码时,可以用此方法来查看优化前后程序所耗费的时间 //Stopwatch类別在System.Diagnostics命名空间里 Stopwatc ...
- [C#] 常用工具类——应用程序属性信息访问类
using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespac ...
- 对类HelloWorld程序中添加一个MessageBox弹窗
对类HelloWorld程序中添加一个MessageBox弹窗 分析: 任一程序运行的时候都会加载kernel32.dll的,但MessageBoxA()这个API却是在user32.dll中的.所以 ...
- YARN 中的应用程序提交
YARN 中的应用程序提交 本节讨论在应用程序提交到 YARN 集群时,ResourceManager.ApplicationMaster.NodeManagers 和容器如何相互交互.下图显示了一个 ...
- 将java开发的wordcount程序提交到spark集群上运行
今天来分享下将java开发的wordcount程序提交到spark集群上运行的步骤. 第一个步骤之前,先上传文本文件,spark.txt,然用命令hadoop fs -put spark.txt /s ...
随机推荐
- Coursera Deep Learning 2 Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week1, Assignment(Regularization)
声明:所有内容来自coursera,作为个人学习笔记记录在这里. Regularization Welcome to the second assignment of this week. Deep ...
- GIT刷新忽略文件.gitignore
1.使用命令工具Git Bash,进入需要修改的工作目录.如C:/est 则输入 cd c:/test 2.重置所有缓存(注意后面有个.) git rm -r --cached . 3.重新添加(注意 ...
- NoClassDefFound Error: com/fasterxml/jackson/annotation/JsonAutoDetect
少了 jackson-annotation https://blog.csdn.net/qq_36497454/article/details/80461676
- Python问题:UnboundLocalError: local variable 'xxx' referenced before assignment
参考链接: http://blog.csdn.net/onlyanyz/article/details/45009697 https://www.cnblogs.com/fendou-999/p/38 ...
- Python问题:'Nonetype' object is not iterable
参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的 ...
- 判断GPS是否开启&转到设置GPS界面
/** * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的 * @param context * @return true 表示开启 */ public static final boo ...
- 【ARTS】01_16_左耳听风-20190225~20190303
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- dubbo源码分析1——SPI机制的概要介绍
插件机制是Dubbo用于可插拔地扩展底层的一些实现而定制的一套机制,比如dubbo底层的RPC协议.注册中心的注册方式等等.具体的实现方式是参照了JDK的SPI思想,由于JDK的SPI的机制比较简单, ...
- requests库入门05-参数类型
一个接口基本都需要传入参数,有的参数必填,有的不必填. params参数 使用params参数来传递接口所需要的参数.一般用在get请求中,url参数是通过?拼接,?前面是接口的地址,之后是请求的参数 ...
- 理解OAuth 2.0(转)
OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛应用,目前的版本是2.0版. 本文对OAuth 2.0的设计思路和运行流程,做一个简明通俗的解释,主要参考材料 ...