CCGTA5888 @ 2019-07-06 15:37:15
#include<bits/stdc++.h>
using namespace std;
int main(){
char str1[256],str2[256];
int a[256],b[256],c[256];
int lena,lenb,lenc;
int x;
int i,j;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
cin>>str1;
cin>>str2;
lena=strlen(str1);
lenb=strlen(str2);
for(i=0;i<=lena-1;i++)
a[lena-i]=str1[i]-'0';
for(i=0;i<=lenb-1;i++)
b[lenb-i]=str2[i]-'0';
for(i=1;i<=lenb;i++)
{
x=0;
for(j=1;j<=lena;j++)
{
c[i+j-1]=a[j]*b[i]+x+c[i+j-1];
x=c[i+j-1]/10;
c[i+j-1]%=10;
}
c[i+lena]=x;
}
lenc=lena+lenb;
while((c[lenc]==0)&&(lenc>1))
lenc--;
for(i=lenc;i>=1;i--)
cout<<c[i];
cout<<endl;
return 0;
}
by Happy_Dream @ 2019-07-06 15:40:11
@CCGTA5888 ,每个数字不超过10^2000,所以你数组和字符数组开小了。应该开到2001才行。
by CCGTA5888 @ 2019-07-06 15:41:06
@yisu 哦,谢谢奆佬