PAT A1112 Stucked Keyboard (20 分)——字符串
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<k≤100) 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 <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <set>
using namespace std;
int n,k,m;
set<char> good,bad,pr;
queue<char> q;
int main(){
scanf("%d",&n);
string s;
cin>>s;
for(int i=;i<s.length()-n+;i++){
char now=s[i];
int flag=;
for(int j=;j<n;j++){
if(s[i]!=s[j+i]){
good.insert(now);
flag=;
break;
}
}
if(flag==){
if(bad.find(now)!=bad.end())bad.erase(bad.find(now));
continue;
}
if(good.find(now)==good.end())bad.insert(now),i=i+n-;
}
for(int i=;i<s.length();i++){
if(bad.find(s[i])!=bad.end() && pr.find(s[i])==pr.end())printf("%c",s[i]),pr.insert(s[i]);
}
printf("\n");
for(int i=;i<s.length();i++){
if(bad.find(s[i])==bad.end())printf("%c",s[i]);
else{
printf("%c",s[i]);
i=i+n-;
}
}
}
注意点:看似简单,实际上还蛮复杂的。看了大佬的思路都是看重复的个数是不是n的倍数,再来判断。但总感觉都落下了一个考虑点,一开始认为是坏的,其实后面证明是好的,这个好像都没有考虑。
PAT A1112 Stucked Keyboard (20 分)——字符串的更多相关文章
- 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)
题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...
- PAT 1112 Stucked Keyboard
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when yo ...
- 【刷题-PAT】A1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise
题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...
- PAT 1112 Stucked Keyboard[比较]
1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...
- pat 1035 Password(20 分)
1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
随机推荐
- Minitab系列 前言
Matlab 在有些时候太过去强大,强大到几乎所有的数学问题都可以解决. 在这里,Matlab就像数学版的Vim,对于一般的使用者还是不想编程,想要更加的直接直观的数学处理工具,这里向大家介绍mini ...
- PHP7.27: connect mysql 5.7 using new mysqli
<!doctype html> <html> <head> <meta name="viewport" content="wid ...
- jQuer插件满屏气泡飘落动画效果
飘落动画效果插件引用: <script src="https://cdn.bootcss.com/JQuery-Snowfall/1.7.4/snowfall.jquery.min.j ...
- js+bootstrap实现分页页码
制作page.jsp,在其他页码引入,只需把最外层的form标签的id设置为myForm: 其中 totalPages:共有多少页:totalElements:共有有多少条记录:currentPage ...
- loadrunner 场景设计-添加Windows Resources计数器
场景设计-添加Windows Resources计数器 by:授客 QQ:1033553122 目的 监控要测试的windows服务器的资源使用情况 步骤 1.添加视图,方法双击.拖动左侧的Windo ...
- 《Inside C#》笔记(十三) 多线程 下
一 任务调度 当一个线程的时间片被用尽后,处理器会切换到另一个线程,但关于如何确定执行哪一个线程呢,这就涉及到了线程或任务的优先级. a) 每个线程都有优先级,任务调度算法会根据各线程的不同优先级来决 ...
- JavaScript大杂烩6 - 理解JavaScript中的this
在JavaScript开发中,this是很常用的一个关键字,但同时也是一个很容易引入bug的一个关键字,在这里我们就专门总结一下页面中可能出现的this关键字(包括几种在其他页面文件中出现的this) ...
- Error: spawn Unknown system errno 203
在用node写代码的时候发现这个错误,google之无解,现在解决,发于此. 事件起因为一个全局模块通过子进程(chind_process)调用另一个全局模块的命令,这个错误就是在命令行通过全局命令调 ...
- mysql常用赋权命令
GRANT 所需权限 ON 库名.表名 TO '账号'@'允许访问的IP地址'; 把中文按需替换掉 所需权限:select.insert.delete.update按需要来. 上面那个允许访问IP ' ...
- 使用虚拟环境virtualenv/Virtualenvwrapper隔离多个python
virtualenv 系统中的多个python混用会导致$PYTHONPATH混乱,或者各个工程对于package的版本要求不同等等情况.有一个简单的解决方案就是用virtualenv来隔离多个pyt ...