题目描述
Point:
1、公式
$$tmp = tmp + a[i] * b$$
2、注意前导0
C++ 代码
#include <iostream>
#include <vector>
using namespace std;
vector<int> mul(vector<int>& a, int b)
{
vector<int> c;
int t = 0;
for(int i = 0; i < a.size() || t; ++ 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()
{
string x;
int b;
cin >> x >> b;
vector<int> a;
for(int i = x.size() - 1; i >= 0; -- i) a.push_back(x[i] - '0');
a = mul(a,b);
for(int i = a.size() - 1; i >= 0; -- i) cout << a[i];
return 0;
}