AcWing 3390. 特殊乘法

48

题目

给定一个 nn 位整数 AA,各位从高到低依次为 a1,a2,…,ana_1,a_2,\dots ,a_n。

给定一个 mm 位整数 BB,各位从高到低依次位 b1,b2,…,bmb_1,b_2,\dots ,b_m。

给定一种特殊乘法,不妨用 ⊗\otimes 来表示,我们规定 A⊗B=∑i=1n∑j=1mai×bjA \otimes B=\sum\limits _{i=1}^n \sum \limits_{j=1}^m a_i \times b_j
例如,123⊗45=1×4+1×5+2×4+2×5+3×4+3×5123 \otimes 45=1×4+1×5+2×4+2×5+3×4+3×5。

对于给定的 AA 和 BB,请你计算并输出 A⊗BA \otimes B 的值。

输入格式
两个整数 AA 和 BB。

输出格式
一个整数,表示 A⊗BA \otimes B 的值。

数据范围
1≤A,B≤1091≤A,B≤10^9

输入样例:

123 45

输出样例:

54

题解 - yxc版本

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    int res = 0;
    for (auto x: a)
        for (auto y: b)
            res += (x - '0') * (y - '0');
    cout << res << endl;
    return 0;
}