You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
764 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], al;
int b[N], bl;
void mul(int a[], int &al, int b[], int &bl) {
int t = 0;
int c[N] = {0};
for (int i = 0; i < al; i++)
for (int j = 0; j < bl; j++)
c[i + j] += a[i] * b[j];
al += bl;
for (int i = 0; i < al; i++) {
t += c[i];
a[i] = t % 10;
t /= 10;
}
// 前导0
while (al > 0 && a[al] == 0) al--;
}
int main() {
string x, y;
cin >> x >> y;
for (int i = x.size() - 1; i >= 0; i--) a[al++] = x[i] - '0';
for (int i = y.size() - 1; i >= 0; i--) b[bl++] = y[i] - '0';
mul(a, al, b, bl);
for (int i = al; i >= 0; i--) printf("%d", a[i]);
return 0;
}