正整数 A 的“*D**A(为 1 位整数)部分”定义为由 A* 中所有 *D**A* 组成的新整数 PA。例如:给定 A=3862767,DA=6,则 A 的“6 部分”*P**A* 是 66,因为 A 中有 2 个 6。
现给定 A、DA、B、DB,请编写程序计算 PA+PB。
输入在一行中依次给出 A、DA、B、DB,中间以空格分隔,其中 0<A,B<1010。
在一行中输出 PA+PB 的值。
3862767 6 13530293 3
399
3862767 1 13530293 8
0
stringstream
,省得自己写转换~#include<bits/stdc++.h>
using namespace std;
int get_num(string s, int x)
{
string ans = "";
for(int i=0;i<s.size();i++)
{
int num = s[i] - '0';
if(num == x)
ans += (char)(x + '0');
}
stringstream ss;
int value = 0;
ss << ans;
ss >> value;
return value;
}
int main()
{
string a, b;
int da, db;
cin >> a >> da >> b >> db;
cout << get_num(a,da) + get_num(b,db);
return 0;
}
https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328
原文:https://www.cnblogs.com/MartinLwx/p/11614123.html