题目链接:http://ac.jobdu.com/problem.php?pid=1083
-
题目描述:
-
写个算法,对2个小于1000000000的输入,求结果。
特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
-
输入:
-
两个小于1000000000的数
-
输出:
-
输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。
-
样例输入:
-
123 45
-
样例输出:
-
54
AC代码:
#include<stdio.h>
int main()
{
int a,b;
int size1,size2;
int result;
while(scanf("%d%d",&a,&b)!=EOF)
{
int buf1[20],buf2[20];
result=0;
size1=size2=0;
while(a!=0)
{
buf1[size1++]=a%10;
a/=10;
}
while(b!=0)
{
buf2[size2++]=b%10;
b/=10;
}
for(int i=0;i<size1;i++)
{
for(int j=0;j<size2;j++)
{
result+=buf1[i]*buf2[j];
}
}
printf("%d\n",result);
}
}