POJ-3673 cow multiplition

来源:互联网 发布:淘宝怎么发布宝贝 编辑:程序博客网 时间:2024/06/05 23:58

Bessie is tired of multiplying pairs of numbers the usual way, so she invented her own style of multiplication. In her style, A*B is equal to the sum of all possible pairwise products between the digits of A and B. For example, the product 123*45 is equal to 1*4 + 1*5 + 2*4 + 2*5 + 3*4 + 3*5 = 54. Given two integers A and B (1 ≤ A, B ≤ 1,000,000,000), determine A*B in Bessie's style of multiplication.

Input

* Line 1: Two space-separated integers: A and B.

Output

* Line 1: A single line that is the A*B in Bessie's style of multiplication.

Sample Input
123 45
Sample Output

54

这道题还是非常简单的,也就是用%和/来处理数据就好,但是在提交的时候出现了一个编译问题,也就是pow函数里面,要用10.0而不是10,是因为重载方面的问题,如果是10的话,那么就不知道该匹配哪个重载函数的参数,这个直接在编译器上没有问题,但是在oj上又出现了编译error,所以证明程序出错,都是程序员的错

#include<iostream>#include<math.h>using namespace std;#define N 15int main(){    long long a,b;    while(cin>>a>>b)    {        int sum = 0;        int i = 0;        int value[N];        int valu2[N];        while(a>0)        {            int hee = i+1;            long help = pow(10.0,hee);            long he = pow(10.0,i);            value[i] =(a%help)/he;            a -= value[i]*pow(10.0,i);            i++;            //cout<<"a"<<" "<<a;        }       // cout<<endl;        int j = 0;        while(b>0)        {            int he = j+1;            long help2 = pow(10.0,he);            long hee = pow(10.0,j);            valu2[j] = (b%help2)/hee;            b-= valu2[j]*pow(10.0,j);            j++;        }       /* for(int k = 0;k<i;k++)            cout<<"value a  "<<value[k]<<"  ";            cout<<endl;        for(int t = 0;t<j;t++)            cout<<"value b  "<<valu2[t]<<"  ";            cout<<endl;*/        for(int k = 0;k<i;k++)            for(int t = 0;t<j;t++)        {            sum += value[k] * valu2[t];        }        cout<<sum<<endl;    }}


0 0