luogu2142 高精度減法(高 高)

2021-08-15 23:33:11 字數 988 閱讀 4787

時空限制    1000ms/128m

高精度減法

輸入格式:

兩個整數a,b(第二個可能比第乙個大)

輸出格式:

結果(是負數要輸出負號)

輸入樣例#1:

輸出樣例#1:

20%資料a,b在long long範圍內

100%資料0法一:陣列模擬

#include#include#includeusing namespace std;

const int n = 10005;

int a[n],b[n],c[n];

void zhuan(string s,int a)

bool isbig(int a,int b)

void sub(int a,int b,int c)

void output(int a)

output(c);

} return 0;

}

法二:過載運算子

#include#include#includeusing namespace std;

const int n = 10005;

struct bigint //預設初始化全0

bigint(string x) //string初始化

bigint operator = (const string &x)

bigint operator - (const bigint &b)

bool operator < (const bigint &b)const

ostream& operator << (ostream &out,const bigint &x) /*需過載輸出流、<、高-高*/

else cout

}

P2142 高精度減法

高精度減法 輸入格式 兩個整數a,b 第二個可能比第乙個大 輸出格式 結果 是負數要輸出負號 輸入樣例 1 2 1 輸出樣例 1 1 20 資料a,b在long long範圍內 100 資料01 include2 include3 include4 include5 using namespace ...

P2142 高精度減法(C )

高精度減法 兩個整數a,b 第二個可能比第乙個大 結果 是負數要輸出負號 輸入 121 輸出 1 20 資料a,b在long long範圍內 100 資料010086 高精度減法,保證大減小即可 include include using namespace std bool cmp vector ...

高精度減法模板(洛谷2142)

洛谷p2142 1 luogu2142,不壓位的高精度減法 2 include 3 include 4 include 56 using namespace std 78 const int max n 11000 9 10int a max n b max n c max n 11string x...