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 大数相乘一直没有a过。今天看了一篇文章,心血来潮,a了这道题,有点小兴奋#include<stdio.h> #include<string.h> int main() { int a[10001],b[10001],len1,len2,i,j,c[1001],k1,k2,k3; char st1[1000],st2[1000],st3[1000]; while(scanf("%s%s",st1,st2)!=EOF) { k2=0; len1=strlen(st1); len2=strlen(st2); for(i=0;i<=len1-1;i++) a[i]=st1[len1-i-1]-'0'; for(i=0;i<=len2-1;i++) b[i]=st2[len2-i-1]-'0'; memset(c,0,sizeof(c)); for(i=0;i<=len1-1;i++) { k2=0; for(j=0;j<=len2-1;j++) { c[i+j]+=a[i]*b[j]; if(c[i+j]>=10) { c[i+j+1]+=c[i+j]/10; c[i+j]=c[i+j]%10; } } } len1+=len2; while(c[len1]==0&&len1!=0) len1--; if(len1==0) printf("0"); else { for(i=len1;i>=0;i--) printf("%d",c[i]); } printf("\n"); } return 0; }