The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12 12 2 222222222222222222222222
Sample Output
144 444444444444444444444444
忘记考虑乘以0的情况。╮(╯▽╰)╭
#include <stdio.h>
#include <string.h>
#define max 600
int c[max];
int change(int a[],char s[])
{int l=strlen(s),i;
for (i=1;i<max;i++)
a[i]=0;
for (i=l-1;i>=0;i--)
a[l-i]=s[i]-'0';
return l;
};
int sort(char s1[],char s2[])
{int l1,l2,a[max],b[max],i,j,len;
l1=change(a,s1);
l2=change(b,s2);
if ((l1==1)&&(s1[0]=='0')) return 1;
if ((l2==1)&&(s2[0]=='0')) return 1;
for (i=1;i<=l1;i++)
for (j=1;j<=l2;j++)
c[i+j-1]=c[i+j-1]+a[i]*b[j];
for (i=1;i<=l1+l2;i++)
{c[i+1]=c[i+1]+c[i]/10;
c[i]=c[i]%10;
}
len=l1+l2+1;
while (c[len]==0) --len;
return len;
};
void main()
{char s1[max],s2[max];
int i,len;
while (gets(s1))
{for (i=1;i<max;i++)
c[i]=0;;
gets(s2);
len=sort(s1,s2);
for (i=len;i>=1;i--)
printf("%d",c[i]);
printf("\n");
}
}