Description
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
For each input pair of lines the output line should consist one integer the product.
12 12 2 222222222222222222222222
144 444444444444444444444444
注意當為0的情況,一開始忽略了這種情況。當任一個為0的時候別忘了輸出0
#include#include #include char str1[1010],str2[1010]; char a[1010],b[1010],sum[1010]; int main() { int len1,len2; int i,j; while (~scanf("%s",str1)) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(sum,0,sizeof(sum)); len1= strlen(str1); for (i=len1-1;i>=0;i--) a[len1-i-1]=str1[i]-'0'; scanf("%s",str2); len2=strlen(str2); for (i=len2-1;i>=0;i--) b[len2-i-1]=str2[i]-'0'; for (i=0;i =10) { sum[j+1]+=sum[j]/10; sum[j]%=10; } } int flag=0; for(i=1010;i>=0;i--) { if(flag||sum[i]) { flag=1; printf("%d",sum[i]); } } if(!flag) printf("0"); printf("\n"); } return 0; }