矢织雾甜 @ 2020-08-25 10:33:05
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char al[101],bl[101];
int a[101],b[101],c[10001],lena,lenb,lenc,i,j,x;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
scanf("%s",al);
scanf("%s",bl);
lena=strlen(al);lenb=strlen(bl);
for(i=0;i<=lena-1;i++)
a[lena-i]=al[i]-48;
for(i=0;i<=lenb-1;i++)
b[lenb-i]=bl[i]-48;
for(i=1;i<=lena;i++)
{
x=0;
for(j=1;j<=lenb;j++)
{
c[i+j-1]=a[i]*b[j]+x+c[i+j-1];
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lenb]=x;
}
lenc=lena+lenb;
while(c[lenc]==0&&lenc>1)
lenc--;
for(i=lenc;i>=1;i--)
cout<<c[i];
cout<<endl;
return 0;
}
最后两个测试点一直TLE,求大佬帮帮忙!!!
by StarLbright40 @ 2020-08-25 10:34:28
把数组开到main函数外面然后删掉memset
by StarLbright40 @ 2020-08-25 10:35:19
建议压位高精(
by 矢织雾甜 @ 2020-08-25 10:38:57
额,刚试了一下,TLE变成了WA,又加一个longlong,结果还是超时....
by 矢织雾甜 @ 2020-08-25 10:40:08
怎么压位?大佬能否讲一下?
by chenxuanzhen @ 2020-08-25 10:52:46
字符数组开小了
by G_E_E_D @ 2020-08-31 19:32:48
推荐使用python做,自带高精