[刷题] 1016 部分A+B (15分)

思路

  • 以字符串形式接收
  • 遍历字符串,组装数据,输出结果
#include <iostream>
using namespace std;
int main() {
    string a, b;
    int da, db, pa = 0, pb = 0;
    cin >> a >> da >> b >> db;
    for (int i = 0; i < a.length(); i++)
        if (da == (a[i] - '0')) pa = pa * 10 + da;
    for (int i = 0; i < b.length(); i++)
        if (db == (b[i] - '0')) pb = pb * 10 + db;
    cout << pa + pb;
    return 0;
}

  

posted @ 2020-10-22 09:29  cxc1357  阅读(88)  评论(0编辑  收藏  举报