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
766 B

2 years ago
#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 = 1; i <= al; i++)
for (int j = 1; j <= bl; j++)
c[i + j - 1] += a[i] * b[j];
al += bl;
for (int i = 1; i <= al; i++) {
t += c[i];
a[i] = t % 10;
t /= 10;
}
// 前导0
while (al > 1 && 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; i--) printf("%d", a[i]);
return 0;
}