include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
vector[HTML_REMOVED] mul(vector[HTML_REMOVED] &A, int b)
{
vector[HTML_REMOVED] C;
unsigned 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; //得到进位
}
//去掉前导0
//while (C.size() > 1 && C.back() == 0)
// C.pop_back();
return C;
}
int main(void)
{
string a; //字符串
vector[HTML_REMOVED] A; //存储a字符串的绝对值
unsigned int b; //正整数
cin >> a >> b;
if (b > 1e4)
return 1;
if (b == 0) {
printf("0");
return 0;
}
//判断a是否负数
if (a[0] == '-') {
//将字符串转换成容器,逆序
for (int i = a.size() - 1; i > 0; --i)
A.push_back(a[i] - '0'); //A[0]是低位
auto C = mul(A, b);
printf("-");
//逆序输出C
for (int i = C.size() - 1; i >= 0; --i)
printf("%d", C[i]);
} else {
//将字符串转换成容器,逆序
for (int i = a.size() - 1; i >= 0; --i)
A.push_back(a[i] - '0'); //A[0]是低位
auto C = mul(A, b);
//逆序输出C
for (int i = C.size() - 1; i >= 0; --i)
printf("%d", C[i]);
}
return 0;
} ``
Markdown炸了