大整数乘普通整数
大整数放在vector里,把普通整数看作一个整体进行运算
#include<iostream>
#include<vector>
using namespace std;
//A为大整数,B为普通整数
vector<int> Mult(vector<int> &A,int B)
{
vector<int> C;
int t = 0;
int k = 0;
for(int i = 0;i<A.size();i++)
{
if(i<A.size()) t = t + A[i] * B;
C.push_back(t%10);
t = t/10;
}
if(t) C.push_back(t);
while(C.size()>1 && C.back()==0) C.pop_back();
return C;
}
int main()
{
string num1;
int num2;
cin>>num1>>num2;
vector<int> A;
for(int i = num1.size()-1;i>=0;i--) A.push_back(num1[i]-'0');
int B = num2;
auto C = Mult(A,B);
for(int i = C.size()-1;i>=0;i--) printf("%d",C[i]);
return 0;
}