高精度加法

2021-08-14 05:33:39 字數 807 閱讀 5465

描述

題目描述:

谷學長有乙個非常簡單的問題給你,給你兩個整數a和b,你的任務是計算a+b。

輸入:輸入的第一行包含乙個整數t(t<=20)表示測試例項的個數,然後2*t行,分別表示a和b兩個正整數。注意整數非常大,那意味著你不能用32位整數來處理。你可以確定的是整數的長度不超過1000。

輸出:對於每乙個樣例,你應該輸出兩行,第一行是"case #:",#表示第幾個樣例,第二行是乙個等式"a+b=sum",sum表示a+b的結果。注意等式中有空格。

樣例輸入21

2112233445566778899

998877665544332211

樣例輸出

case 1:

1 + 2 = 3

case 2:

112233445566778899 + 998877665544332211 = 1111111111111111110

#include

#include

#include

#include

using namespace std;

int main()

int lll=ll-1;

if(a[ll-1]+b[ll-1]>10)

printf("case %d:\n",i);

printf("%s + %s = ",s1,s2);

for(int i=lll;i>=0;i--)

printf("%d",c[i]);

printf("\n");

i++;

}return 0;

} 完美ac~

python高精度加法 高精度加法

1.思路 其實就是模擬,加法是最簡單的,從個位開始加,價位加到前一位,然後再取10的餘數。for int i 1 i len i 計算和 c i a i b i 進製 c i 1 c i 10 取10的餘數 c i 10 2.實現 int len max a.length b.length 倒著存,...

高精度加法 高精度減法

雖然以前自己就學習過,但是自己打出來的 目測效率不高,也不夠精簡 因此學習一下eden裡面的這一題 big integer add subtract ifndef big integer define big integer include include using std string usin...

高精度加法

program gjplus vars1,s2,s3,st,s string i,j,k,l1,l2,li,n1,n2,n3,n4 integer begin readln s1 readln s2 l1 length s1 l2 length s2 if l1 l2 then li l1 else...