描述
高精度乘法
輸入:兩行,每行表示乙個非負整數(不超過10000位)
輸出:兩數的乘積。
樣例輸入:
99101
copy
樣例輸出:
9999
copy
限制各個測試點1s
#include #include#include
#include
#include
using
namespace
std;
#define max 10001
void bigmul(string a, string
b), b[max] = , sum[max*2] = ;
int length_a =a.length();
int length_b =b.length();
for(int i = 1, j = length_a-1; i <= length_a; i++, j--)
a[i] = a[j] - '0'
;
for(int i = 1, j = length_b-1; i <= length_b; i++, j--)
b[i] = b[j] - '0'
; memset(sum,
0, sizeof
(sum));
int length_sum = 0
;
for(int i = 1; i <= length_a; i++) //
用陣列模擬運算
}for(int i = 1; i <= length_sum; i++) //
進製處理
}while(sum[length_sum] == 0 && length_sum != 1) //
高位去零
length_sum--;
for(int i = 1, j = length_sum; i <= length_sum; i++, j--)
cout
<}int
main()
高精度減法,高精度乘法
高精度減法 oj資料偏弱如果新增乙個101 2就錯了,下面這一步是為了防止錯誤的 if a aa 0 可能出現第一位的1被借走的的情況,所以加乙個while找第乙個不是0的 while c i 0 i include include include include include include u...
高精度乘法
問題描述 給你兩個正整數a,b,計算它們的乘積。輸入格式 第一行乙個正整數a 第二行乙個正整數b 輸出格式 一行,表示a b 樣例輸入 111222333444555666777888999 999888777666555444333222111 樣例輸出 提示 a,b分別不超過100000位 ff...
高精度乘法
include include include includeusing namespace std const int maxn 5000 inline int get struct data data operator const data b for int i 1 i c.len i whi...