PAT 1112 Stucked Keyboard
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.
Now given a resulting string on screen, you are supposed to list all the possible stucked keys, and the original string.
Notice that there might be some characters that are typed repeatedly. The stucked key will always repeat output for a fixed k times whenever it is pressed. For example, when k=3, from the string thiiis iiisss a teeeeeest
we know that the keys i
and e
might be stucked, but s
is not even though it appears repeatedly sometimes. The original string could be this isss a teest
.
Input Specification:
Each input file contains one test case. For each case, the 1st line gives a positive integer k (1) which is the output repeating times of a stucked key. The 2nd line contains the resulting string on screen, which consists of no more than 1000 characters from {a-z}, {0-9} and _
. It is guaranteed that the string is non-empty.
Output Specification:
For each test case, print in one line the possible stucked keys, in the order of being detected. Make sure that each key is printed once only. Then in the next line print the original string. It is guaranteed that there is at least one stucked key.
Sample Input:
3
caseee1__thiiis_iiisss_a_teeeeeest
Sample Output:
ei
case1__this_isss_a_teest
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int main(){
int k;
cin >> k;
string s;
cin >> s;
unordered_map<char,int> mp; for(int i=;i < s.size();i++){
int cnt = ;
for(int j=i;j < s.size() && j < i+k;j++){
if(s[i] == s[j])cnt++;
}
if(cnt == k)mp[s[i]] = ;
}
for(int i=;i < s.size();){
int cnt = ;
for(int j=i;j < s.size() && j < i+k;j++){
if(s[i] == s[j])cnt++;
}
if(cnt < k){mp[s[i]] = ;i++;}
else if(cnt == k) i += k;
} unordered_map<char,int> mmp = mp;
for(int i=;i < s.size();i++){
if(mmp[s[i]]){
cout << s[i];
mmp[s[i]] = ;
}
} cout << endl; for(auto it=mp.begin();it!=mp.end();it++){
if(it->second == ){
char x = it->first;
for(int i=;i < s.size();i++){
if(s[i] == x){s.erase(i,k-);}
}
}
} cout << s; return ;
}
_unordered_map 不能保证按修改的顺序输出!需要重新按照顺序输出map中的内容。
但学会了对拍!!
PAT 1112 Stucked Keyboard的更多相关文章
- PAT 1112 Stucked Keyboard[比较]
1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...
- PAT甲级——1112 Stucked Keyboard (字符串+stl)
此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078 1112 Stucked Keyboa ...
- 1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- PAT 甲级 1112 Stucked Keyboard
https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...
- PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)
题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...
- PAT (Advanced Level) 1112. Stucked Keyboard (20)
找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...
- 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)
题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...
- PAT甲级 1112 Stucked Keyboard
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 这道题初次写的时候,思路也就是考虑 ...
- PAT A1112 Stucked Keyboard (20 分)——字符串
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...
随机推荐
- 【托业】【跨栏】REVIEW2
supervise vt&vi 监督; 管理; 指导; storage capacity 存储空间,存储能力 be about to do sth =be going to do sth 将做 ...
- MySQL Backup mydumper
生产环境中有一实例每天使用mysqldump备份时长达到了2个小时53分钟,接近3个小时,还不算上备份文件归档的时间,这个时间对于逻辑备份来说有点久.为了提高逻辑备份效率,打算替换为使用mydumpe ...
- metasploit安装,按官网说明
mkdir -p $HOME/git cd $HOME/git git clone git@github.com:YOUR_USERNAME_FOR_GITHUB/metasploit-framewo ...
- python操作wifi
python连接wifi需要使用pywifi包,可以用pip install pywifi安装 1.导入包 import pywifi,time #保存包中写义的常量 from pywifi impo ...
- windows程序设计 MessageBox消息框
MessageBox函数 int WINAPI MessageBoxW( HWND hWnd,//窗口句柄 LPCWSTR lpText,//消息框主体显示的字符串 LPCWSTR lpCaption ...
- window中普通用户无法登录远程桌面
解决方案就是将该用户加到 Remote Desktop Users 这个用户组中. 使用命令 net localgroup "Remote Desktop Users" 用户名 / ...
- IP2——IP地址和子网划分学习笔记之《子网掩码详解》
2018-05-04 16:21:21 在学习掌握了前面的<进制计数><IP地址详解>这两部分知识后,要学习子网划分,首先就要必须知道子网掩码,只有掌握了子网掩码这部分内容 ...
- [macOS] Error: /usr/local must be writable!" (Sierra 10.12 )
Error: /usr/local must be writable!" (Sierra 10.12 ) solution: sudo chown -R $(whoami) /usr/loc ...
- Hadoop 配置文件 & 启动方式
配置文件: 默认的配置文件:相对应的jar 中 core-default.xml hdfs-default.xml yarn-default.xml mapred-default.xml 自定义配置文 ...
- springMVC学习路线3-整合spring(annotion方式)
个人认为使用框架并不是很难,关键要理解其思想,这对于我们提高编程水平很有帮助.不过,如果用都不会,谈思想就变成纸上谈兵了!!!先技术,再思想.实践出真知. 1.基本概念 1.1 Spring Sp ...