很简单的大数乘法,注意俩个数中有一个为零的特殊情况就行,因此WA了一次:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstdlib>
int main()
{
char s[255],s1[255];
int s2[510];
while(~scanf("%s%s",s,s1))
{
if(s[0]=='0'||s1[0]=='0')
{
printf("0\n");
continue;
}
memset(s2,0,sizeof(s2));
int len=strlen(s);
int len1=strlen(s1);
int flag=-1;
int len2;
for(int i=len-1;i>=0;i--)
{
flag++;
int c=0;
len2=500-flag;
for(int j=len1-1;j>=0;j--,len2--)
{
s2[len2]=s2[len2]+c+(s[i]-'0')*(s1[j]-'0');
c=s2[len2]/10;
s2[len2]%=10;
}
while(c!=0)
{
s2[len2]=s2[len2]+c;
c=s2[len2]/10;
s2[len2]%=10;
len2--;
}
}
int i;
for(i=0;i<=500;i++)
if(s2[i]!=0) break;
for(;i<=500;i++)
printf("%d",s2[i]);
printf("\n");
}
return 0;
}