#include<iostream>//矿枝
#include<cstring>//矿枝
using namespace std;
string mul(string sa, string sb) {
string ans = "";
if (sa[0] == '0' || sb[0] == '0') {
return "0";
}
int a[6000], b[6000], c[6000];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
int la = sa.size();
int lb = sb.size();
for (int i = 0; i < la; i++) {
a[la - i - 1] = sa[i] - '0';
}
for (int i = 0; i < lb; i++) {
b[lb - i - 1] = sb[i] - '0';
}
for (int i = 0; i < la; i++) {
for (int j = 0; j < lb; j++) {
c[i + j] += a[i] * b[j];
c[i + j + 1] += c[i + j] / 10;
c[i + j] %= 10;
}
}
int lc = la + lb;
while (c[lc - 1] == 0 && lc > 0) {
lc--;
}
for (int i = lc - 1; i >= 0; i--) {
char tmp = c[i] + '0';
ans = ans + tmp;
}
return ans;
}
int main() {
string a, b;
cin >> a >> b;
cout << mul(a, b);
return 0;
}
高精度乘法
最新推荐文章于 2024-11-13 19:55:24 发布