题意
对于给定的数字A和B
,各自提取只包含指定字符DA和DB
的子序列,对两个子序列求和输出。
思路
模拟即可。注意范围,需要int64_t
。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string a, b;
int da, db;
cin >> a >> da >> b >> db;
auto solve = [](string s, int d) {
int64_t res = 0;
for (int i = 0; i < s.size(); ++i) {
s[i] -= '0';
if (s[i] != d) continue;
res = res * 10 + s[i];
}
return res;
};
cout << solve(a, da) + solve(b, db) << '\n';
return 0;
}
HINT
不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !