AcWing 791. 高精度加法(高精度乘低精度)
作者:
acwing_Fa
,
2024-09-13 16:12:26
,
所有人可见
,
阅读 1
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
using ll=long long;
vector<int> mul(vector<int>& a,int b)
{
//高精度乘法
int t=0;
vector<int> c;
for(int i = 0;i < a.size() || t != 0 ; ++i)
{
if(i < a.size())t += a[i] * b;
c.push_back(t%10);
t/=10;
}
while(c.size() > 1 && c.back() == 0)c.pop_back();
return c;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string A;
int b;
cin>>A>>b;
vector<int>a;
for(int i = A.size() - 1;i >= 0;--i)a.push_back(A[i]-'0');
vector<int> c = mul (a, b);
for(int i = c.size() - 1; i >= 0 ;--i)cout<<c[i];
return 0;
}