cjweffort

博客园 首页 联系 订阅 管理

http://ac.jobdu.com/problem.php?cid=1040&pid=38

题目描述:

写个算法,对2个小于1000000000的输入,求结果。

特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

输入:

 两个小于1000000000的数

输出:

 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。

样例输入:
123 45
样例输出:
54

// 题目39:特殊乘法.cpp: 主项目文件。

#include "stdafx.h"
#include <cstdio>

int distinctMulitply(int a,int b)
{
	int arrA[11],arrB[11];
	int cntA=0,cntB=0;
	while(a)
	{
		arrA[cntA++]=a%10;
		a/=10;
	}
	while(b)
	{
		arrB[cntB++]=b%10;
		b/=10;
	}
	int res=0;
	for(int i=0;i<cntA;i++)
		for(int j=0;j<cntB;j++)
			res+=arrA[i]*arrB[j];
	return res;
}

int main()
{
    int a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		int res=distinctMulitply(a,b);
		printf("%d\n",res);
	}
    return 0;
}


posted on 2013-03-05 11:34  cjweffort  阅读(235)  评论(0)    收藏  举报