题目描述
Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros).FJ asks that you do this yourself; don't use a special library function for the multiplication.
输入格式
* Lines 1..2: Each line contains a single decimal number.输出
* Line 1: The exact product of the two input lines样例输入
111111111111111111111111
样例输出
12345679011110987654321
#include<stdio.h>
#include<string.h>
int main (){
char a[50],b[50],sum[200];
int i,j,l,y,m,p=-1,q=-1;
scanf("%s %s",&a,&b);
l=strlen(a)+strlen(b)-1;
for(i=0;i<=l;i++) sum[i]='0';
for(j=strlen(b)-1;j>=0;j--){
y=0;p++;q=-1;;
for(i=strlen(a)-1;i>=0;i--){
q++;
m=(b[j]-'0')*(a[i]-'0')+sum[q+p]-'0';
sum[p+q]=(m+y)%10+'0';
y=(m+y)/10;
if(i==0) sum[p+q+1]=y+'0';
}
}
if(sum[l]=='0') i=l-1;
else i=l;
for(;i>=0;i--)
printf("%c",sum[i]);
printf("\n");
}