数位拆解(从int获取每一位)

# include<iostream>
# include<string>
# include<vector>
# include<algorithm>
# include<cmath>
# include<cstdio>
# include<map>
# include<stack>
using namespace std;


vector<int> res1;
vector<int> res2;

void print(vector<int> res) {
    for ( int i = 0; i <= res.size() - 1 ; i++) {
        cout << res[i] << " ";
    }
    cout << endl;
}




int getResult(int a, int b) {

    while ( a > 0) {
        res1.push_back(a % 10); // 1234 -> 4 3 2 1
        a /= 10;
    }
    reverse(res1.begin(),res1.end());


    while (b > 0) {
        res2.push_back(b % 10); // 4 3 2 1
        b /= 10;
    }
    reverse(res2.begin(),res2.end());
   // print(res1);
   // print(res2);


    int res = 0;
    for ( int i = 0; i <= res1.size() - 1 ; i ++) {
        for ( int j = 0; j <= res2.size() - 1 ; j++) {
            //cout << res1[i] * res2[12j] << " ";
            res += res1[i] * res2[j];

        }
    }
    return res;


}






int main() {

    int a, b;
    cin >> a >> b;
    cout << getResult(a, b) << endl;



}

 

数位拆解(从int获取每一位)数位拆解(从int获取每一位) bijingrui 发布了20 篇原创文章 · 获赞 0 · 访问量 1554 私信 关注
上一篇:HDU-6563 Strength (贪心)


下一篇:GDB调式工具学习笔记---单步执行和跟踪函数调用