您的位置:首页 > 其它

九度OJ-1083-特殊乘法

2017-02-03 23:56 381 查看
题目地址:点击打开链接题目描述:

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

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

 两个小于1000000000的数
输出:

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

样例输出:
54

来源:2010年清华大学计算机研究生机试真题答疑:解题遇到问题?分享解题心得?讨论本题请访问:http://t.jobdu.com/thread-7806-1-1.html
#include <iostream>
using namespace std;

int main(){
int a,b;
int anum[10],bnum[10];
int acount,bcount;
int temp,sum;
while (cin>>a>>b){
//initiate
sum=0;
//process
for (acount=0,temp=a;temp>0;acount++){
anum[acount]=temp%10;
temp/=10;
}
for (bcount=0,temp=b;temp>0;bcount++){
bnum[bcount]=temp%10;
temp/=10;
}
//sum up
for (int i=0;i<acount;i++){
for (int j=0;j<bcount;j++){
sum+=anum[i]*bnum[j];
}
}
//output
cout<<sum<<endl;
}
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数学问题