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 ...
随机推荐
- 4、Flutter 采坑记录篇二_依赖库不兼容
1.报错信息 Because every version of flutter_test from sdk depends on package_resolver 1.0.4 which depend ...
- 基于容器与微服务架构的Web应用示例eShopOnContainers
简介 微软官方提供了一个基于Docker和微服务的示例应用eShopOnContainers:它使用了面向服务的架构并且从服务端到客户端都是跨平台的:该架构使用通过http作为客户端与服务端直接的通信 ...
- Fiddler和PostMan的使用例子和下载
一.Fiddler:先下个 1.先讲下Get请求:很简单就一图示意: 然后再讲下POST:举个例子 请求主体的内容: User-Agent: FiddlerContent-Type: applicat ...
- Linux下的.txt文件复制到win下面不自动换行
原因:在Linux系统下, '\n'就是一个换行符,而在windows下,它是由回车换行组成,表示为 \r\n 解决方法:用Notepad++打开文档-->编辑-->文档格式转换--> ...
- C#-MVC-Razor视图引擎及解决路径问题的三个方法
Razor 视图引擎 与Aspx开发区别在于代码: 1.Razor 更智能,摒弃了<%%>格式,直接用@符号开启cs代码,遇到html时自动识别 2.遇到如汉字等即非cs代码,又非html ...
- uboot移植阶段二--3串口终结篇
2011-03-20 23:00:37 前天U-boot移植串口后,能成功显示数据. 今天的主要目的是再次进行U-boot移植.看是否成功.花了40分钟,很顺利. 接着就是要把之前有问题的U-boot ...
- 解决tomcat重启时报严重: Exception loading sessions from persistent storage的问题
很多项目在重启时会报:严重: Exception loading sessions from persistent storage的问题.该问题的原因是tomcat的session持久化机制引起的,t ...
- 《CSS世界》读书笔记(九)
<!-- <CSS世界>张鑫旭著 --> content内容生成技术 1. content 辅助元素生成 清除浮动: .clear:after { content: ''; d ...
- 模块 import 与from
什么是模块:就是一系列功能的集合体 模块的来源 :1内置模块 2 第三方模块 3 自定义模块 模块的格式: 1 使用python编写的.py文件 2 已被编译为共享库或DLL的C或C++扩展 ...
- windbg无故不显示command窗口
原文最早发表于百度空间2010-02-05 有的dump可以显示,有的不行……上网找了一通没有收获,自己搞了一下,终于在点击“window”——“cascade floating windows”后出 ...