高精度×高精度
作者:
德智体美劳
,
2025-04-22 17:57:18
· 广东
,
所有人可见
,
阅读 3
#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
string a, b;
vector<int> A, B;
int ans[N * 2];
void mult(vector<int> A, vector<int> B)
{
for (int i = 0; i < A.size(); i++)
{
for (int j = 0; j < B.size(); j++)
{
ans[j + i] += A[i] * B[j];
if (ans[i + j] >= 10)
{
ans[i + j + 1] += ans[i + j] / 10;
ans[i + j] %= 10;
}
}
}
int pos = 0;
for (int i = A.size() + B.size() - 1; i >= 0; i--)
if (ans[i] != 0)
{
pos = i;
break;
}
for (int i = pos; i >= 0; i--) cout << ans[i];
}
int main()
{
cin >> a >> b;
for (int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0');
for (int i = b.size() - 1; i >= 0; i--) B.push_back(b[i] - '0');
mult(A, B);
return 0;
}