cccyyylll888 @ 2020-08-05 19:05:49
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int A[1020];
int mul[1020];
void BIGcin(string s,int a[])
{
int la = s.length();
for (int i = 1;i <= la;i++)
{
a[i] = s[la - i] - '0';
}
a[0] = la;
}
void BIGcout(int a[])
{
int len = a[0];
for (int i = len;i >= 1;i--)
{
cout << a[i] ;
}
cout << endl;
}
void BIGmul(int a[],int b,int mul[])
{
int la = a[0];
int len = la;
int u = 0;
for(int i = 1;i <= len;i++)
{
int t = (a[i] * b + u);
mul[i] = t % 10;
u = t / 10;
}
while(u > 0)
{
len++;
mul[len] = u % 10;
u /= 10;
}
mul[0] = len;
}
int main()
{
string a;
int b;
cin >> a >> b;
BIGcin(a,A);
BIGmul(A,b,mul);
BIGcout(mul);
return 0;
}
by dead_X @ 2020-08-05 19:11:58
目测数组开小,开到4000吧
by 荣耀南冥 @ 2020-08-05 19:12:41
@cccyyylll888 数据范围是10的2000次方,数组至少到2001吧
by 荣耀南冥 @ 2020-08-05 19:13:19
@cccyyylll888 而且你的输出函数不对,你试试输入100 0最后输出是000,答案应该是0
by 荣耀南冥 @ 2020-08-05 19:15:43
@cccyyylll888 建议输出函数这样写,伪代码
result[]//结果数组
len//长度
while(!result[len])len--;
if(len==0)printf("0");
else {
for (int i = len;i >= 1;i--){
cout << a[i] ;
}
cout << endl;
}
by Smile_Cindy @ 2020-08-05 19:49:13
@cccyyylll888 请仔细读题。