1 13 09 大整數乘法

2021-10-19 23:41:48 字數 664 閱讀 8484

描述

求兩個不超過200位的非負整數的積。

輸入有兩行,每行是乙個不超過200位的非負整數,沒有多餘的前導0。

輸出一行,即相乘後的結果。結果裡不能有多餘的前導0,即如果結果是342,那麼就不能輸出為0342。

樣例輸入

12345678900

98765432100

樣例輸出

1219326311126352690000

#include

#include

using

namespace std;

char s1[

300]

, s2[

300]

;int a[

300]

,b[300

],c[

600]

;int

main()

for(

int i=

0;i) len = len1+len2;

//乘積的位數不超過兩個乘數長度的和

for(

int i=

0;i}while

(len && c[len]==0

)while

(len>=0)

return0;

}

大整數乘法

參考 http hi.baidu.com operationsystem blog item 6e45dd1af1acadf3ae51330b.html 在計算機中,長整型 long int 變數的範圍是 2147483648 至 2147483647,因此若用長整型變數做乘法運算,乘積最多不能超過...

大整數乘法

問題描述 by 計算機演算法設計與分析 王曉東 p17 通常,在分析乙個演算法的計算複雜性時,都將加法和乘法運算當作是基本運算來處理,即將執行一次加法或乘法運算所需的計算時間當作乙個僅取決於計算機硬體處理速度的常數。這個假定僅在計算機硬體能對參加運算的整數直接表示和處理時才是合理的。然而,在某些情況...

大整數乘法。

include using namespace std int multi int num1,int size1,int num2,int size2 int size size1 size2 int ret new int size int i 0 for i 0 iret i 0 for i 0...