正整数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<iostream>
#include<string>
using namespace std;
int main() {
string A, B;
int Da, Db;
int Pa = 0, Pb = 0;
cin >> A >> Da >> B >> Db;
for (string::iterator it = A.begin(); it != A.end(); it++)
if ((*it - '0') == Da)
Pa = Pa * 10 + Da;
for (string::iterator it = B.begin(); it != B.end(); it++)
if ((*it - '0') == Db)
Pb = Pb * 10 + Db;
cout << Pa + Pb;
return 0;
}