高精度模板

2021-08-26 22:42:56 字數 1633 閱讀 4649

《高精度模板》

#include #include #include #include #include using namespace std;

#define maxsize 1005

//建立乙個結構體

struct hp

;//copy 函式把b copy給a

void copy(hp &a,hp &b)

//輸入函式

void input(hp &a,string str)

//輸出函式

void print(const hp &y)

}if(c.s[len+1]>0) //最後一位有進製情況

len++;

c.len=len;}/

2 高精度減法

void subtract(const hp &a,const hp &b,hp &c)

}while(len>1&&c.s[len]==0)

len--;//捨去前面的0

c.len=len;}/

3 高精度比較

int compare(const hp &a,const hp &b)

/4高精度*單精度

void multiply(const hp &a,int b,hp &c)

//處理進製

len++;

while(c.s[len]>=10)

while(len>1&&c.s[len]==0)

len--;//捨去前面沒用的0

c.len=len;}/

5高精度*高精度

void multiplyh(const hp &a,const hp &b,hp &c)

len=a.len+b.len+1;

while(len>1&&c.s[len]==0)

len--;//捨去前面沒用的0

c.len=len;}/

6高精度/單精度

void divide(const hp &a,int b,hp &c,int &d)  

while(len>1&&c.s[len]==0)

len--;//捨去前面沒用的0

c.len=len;}/

7 高精度*10

void multiply10(hp &a)

/8 高精度/高精度  

void divideh(const hp &a,const hp &b,hp &c,hp &d)

len=a.len;

d.len=1;

for(i=len;i>=1;i--)

}while(len>1&&c.s[len]==0)

len--;//捨去前面沒用的0

c.len=len;

}///

hp sum[1003];//建立乙個結構體陣列

int main()

for(int i=0;i<1002;i++)

a.len=1;

b.s[1]=2 ;

sum[1].s[1]=2;

sum[2].s[1]=1;

b.len=1;

int pos=2;

if(n>2)

return 0;

}

高精度模板

include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum bignum const int 將乙個int型別的變數轉化為大數 big...

高精度模板

include include include include include using namespace std const int maxn 1000 struct bign bign operator const char num 過載運算子 bign const char num 支援初...

高精度模板

include include include includeusing namespace std define maxn 9999 define maxsize 10 define dlen 4 class bignum 建構函式 bignum const int 將乙個int型別的變數轉化為大...