正整数 A 的“DA(为 1 位整数)部分”定义为由 A 中所有 DA 组成的新整数 PA。例如:给定 A=3862767,DA=6,则 A 的“6 部分”PA 是 66,因为 A 中有 2 个 6。
现给定 A、DA、B、DB,请编写程序计算 PA+PB。
输入格式:
输入在一行中依次给出 A、DA、B、DB,中间以空格分隔,其中 0<A,B<1010。
输出格式:
在一行中输出 PA+PB 的值。
输入样例 1:
3862767 6 13530293 3
输出样例 1:
399
输入样例 2:
3862767 1 13530293 8
输出样例 2:
0
#include<bits/stdc++.h>
using namespace std;
int main() {
string a, b;
char da, db;
cin >> a >> da >> b >> db;
int aa=0, bb=0;
for (auto it = a.begin(); it != a.end(); ++it) {
if (*it == da)
aa = aa * 10 + (*it-'0');
}
for (auto it = b.begin(); it != b.end(); ++it) {
if (*it == db)
bb = bb * 10 + (*it-'0');
}
cout << aa + bb;
return 0;
}