您的位置:首页 > 其它

九度OJ 1083: 特殊乘法

2014-01-26 23:16 239 查看
题目描述:

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

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

 两个小于1000000000的数
输出:

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

样例输出:
54

来源:
2010年清华大学计算机研究生机试真题

题目分析:

乘法分配率的水题。

源代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int m, n;
while(scanf("%d%d", &m, &n) != EOF)
{
int a = 0;
int b = 0;
while(m)
{
a += m%10;
m /= 10;
}
while(n)
{
b += n%10;
n /= 10;
}
printf("%d\n", a*b);
}
//system("pause");
return 0;
}
/**************************************************************
Problem: 1083
User: superlc320
Language: C++
Result: Accepted
Time:0 ms
Memory:1020 kb
****************************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  九度OJ