高精度乘法
作者:
愛_
,
2024-11-21 12:23:57
,
所有人可见
,
阅读 2
#include<cstring>
#include<vector>
#include<cstdio>
#include<iostream>
using namespace std;
vector<int> mul(vector<int>&A, vector<int>&B)
{
vector<int>c(A.size()+B.size());
int t = 0;
for (int i = 0; i < A.size(); i++)
for (int j = 0; j < B.size(); j++)
c[i+j] += A[i] * B[j];
for(int i = 0;i<c.size();i++)
{
t += c[i];
c[i]=(t%10);
t /= 10;
}
while (t > 0) {
c.push_back(t % 10);
t /= 10;
}
return c;
}
int main()
{
string a,b;
vector<int> A,B;
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');
auto c = mul(A,B);
for(int i = c.size()-1;i>=0;i--)cout<<c[i];
}