PAT 甲级 1084 Broken Keyboard
简单哈希
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
string s1, s2;
cin >> s1 >> s2;
vector<bool> is_break_key(512, false);
for (auto i : s1) {
is_break_key[toupper(i)] = true;
}
for (auto i : s2) {
is_break_key[toupper(i)] = false;
}
for (auto i : s1) {
if (is_break_key[toupper(i)]) {
cout << char(toupper(i));
is_break_key[toupper(i)] = false;
}
}
}
简洁但复杂度高的暴力
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
string s1, s2;
cin >> s1 >> s2;
string ans;
for (auto i : s1) {
if (s2.find(i) == string::npos && ans.find(toupper(i)) == string::npos) {
ans.push_back(toupper(i));
}
}
cout << ans;
}