AcWing 793. 高精度乘法-万用乘法
原题链接
简单
作者:
acxrqqqqq
,
2024-04-17 20:06:43
,
所有人可见
,
阅读 3
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
const int N = 3e3 + 5;
typedef pair<int, int> P;
int a[N], b[N], c[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string A, B;
cin >> A >> B;
int la = 0;
for (int i = A.size() - 1; i > -1; --i) a[++la] = A[i] - '0';
int lb = 0;
for (int i = B.size() - 1; i > -1; --i) b[++lb] = B[i] - '0';
for (int i = 1; i <= la; ++i)
for (int j = 1; j <= lb; ++j)
c[i + j - 1] += a[i] * b[j];
int lc = 0;
for (int i = 1; i <= la + lb - 1||c[i]>9; ++i) {
lc++;
if (c[i] > 9) {
c[i + 1] += c[i] / 10;
c[i] = c[i] % 10;
}
}
lc++;
while (lc > 1 && c[lc] == 0) lc--;
for (int i = lc; i>= 1; --i) cout << c[i];
}