

#include <iostream>
#include <string>
using namespace std;
//逐个对比,合成新整数
int combine(string n, int dn){
int temp = 0;
for (int i = 0; i < n.length(); i++) {
if (n[i] - '0' == dn) {
temp = temp * 10 + dn;
}
}
return temp;
}
int main(){
string a, b;
int da,db;
cin >> a >> da >> b >> db;
cout << combine(a,da) + combine(b,db);
return 0;
}
本文介绍了一种从两个字符串中分别提取指定数字,并将这些数字合成新的整数的方法。通过遍历字符串,对比每个字符,如果字符匹配指定的数字,则将其添加到新的整数中。最终,将两个字符串中提取的数字相加并输出。
1424

被折叠的 条评论
为什么被折叠?



