-
题目地址:点击打开链接
题目描述:
-
写个算法,对2个小于1000000000的输入,求结果。
特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
-
输入:
-
两个小于1000000000的数
-
输出:
-
输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。
-
样例输入:
-
123 45
-
样例输出:
-
54
-
答疑:
- 解题遇到问题?分享解题心得?讨论本题请访问: 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;
}