题解:P17036 [NWERC 2020] 键盘故障 / Keyboardd
a_small_OIer · · 题解
P17036 [NWERC 2020] 键盘故障 / Keyboardd
题意简述
给定两个字符串
解法
问题分析
由于每个粘滞按键在输入时,其每次出现都会导致输出两个相同字符,因此对于任意字符
- 若
c 不是粘滞按键,则它在t 中的出现次数等于在s 中的出现次数。 - 若
c 是粘滞按键,则它在t 中的出现次数等于在s 中出现次数的两倍。
因此我们只需分别统计
复杂度分析
统计次数需要遍历两个字符串,时间复杂度
code
#include <bits/stdc++.h>
#define N 1010
using namespace std;
typedef long long LL;
//十年OI一场空,不开long long见祖宗
string s , t;
map<char , int> ms , mt;
set<char> ans;
int main(){
//freopen(".in" , "r" , stdin);
//freopen(".out" , "w" , stdout);
getline(cin , s);
getline(cin , t);
for(int i = 0 ; i < s.size() ; ++i)
ms[s[i]] += 1;
for(int i = 0 ; i < t.size() ; ++i)
mt[t[i]] += 1;
for(auto i : ms){
if(i.second < mt[i.first])
ans.insert(i.first);
}
for(auto i : ans)
printf("%c" , i);
return 0;
}