Special multiplication (Cartesian product)

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/u011544909/article/details/80029889

Links: https://www.nowcoder.com/questionTerminal/a5edebf0622045468436c74c3a34240f
Source: Cattle-off network

Write algorithm, the input to one billion two small, find results. Special multiplication Example: 1 123 * 45 * 4 + 1 = 5 + 2 * 4 + 2 * 3 * 4 * 5 + 3 + 5 *
Input Description:
two less than the number of 1,000,000,000

Output Description:
Input may have multiple sets of data, for each set of data, the number of output two Input calculation result obtained in the method according to the requirements of the subject.
Example 1
Input
123 45
Output
54


Thought, the number corresponding to the Cartesian product of the two numbers and then adding the respective bits of the multiplication
i.e., for the 123 and 6,45 and 9, 54 so obtained.

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;

    while(cin>>n>>m)
    {
        int t1=0,t2=0;
        while(n)
        {
            t1+=n%10;
            n/=10;
        }
        while(m)
        {
            t2+=m%10;
            m/=10;
        }
        cout<<t1*t2<<endl;
    }

    return 0;
}

Guess you like

Origin blog.csdn.net/u011544909/article/details/80029889