AcWing 793. 高精度乘法 重载*运算符
原题链接
简单
作者:
Snrise
,
2024-04-16 20:36:31
,
所有人可见
,
阅读 1
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define int long long
#define endl '\n'
using namespace std;
vector<int> operator*(vector<int> A, int b)
{
int t = 0;
vector<int> C;
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.back() == 0 && C.size() > 1)
{
C.pop_back();
}
return C;
}
signed main(void)
{
std::ios::sync_with_stdio(false);
string a;
int b;
vector<int> A;
cin >> a >> b;
for (int i = a.size() - 1; i >= 0; i--)
{
A.push_back(a[i] - '0');
}
vector<int> C = A * b;
for (int i = C.size() - 1; i >= 0; i--)
{
cout << C[i];
}
cout << endl;
return 0;
}