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 分)——字符串的更多相关文章

  1. 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)

    题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...

  2. PAT 1112 Stucked Keyboard

    1112 Stucked Keyboard (20 分)   On a broken keyboard, some of the keys are always stucked. So when yo ...

  3. 【刷题-PAT】A1112 Stucked Keyboard (20 分)

    1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...

  4. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  5. PAT 1112 Stucked Keyboard[比较]

    1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...

  6. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  7. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  8. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  9. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

随机推荐

  1. maven配置之:<distributionManagement>snapshot快照库和release发布库

    在使用maven过程中,我们在开发阶段经常性的会有很多公共库处于不稳定状态,随时需要修改并发布,可能一天就要发布一次,遇到bug时,甚至一天要发布N次.我们知道,maven的依赖管理是基于版本管理的, ...

  2. 性能监控(2)–linux下的vmstat命令

    vmstat它可以统计CPU.内存使用情况.swap使用情况等信息.它还可以指定采样周期和次数.

  3. LVOOP设计模式在路上(二)-- 策略模式

    前言 最近工作还挺忙的,连着好些周都是单休了,今天休息在家就来写写关于策略模式的理解和labivew的实现. 正文 1.什么是策略模式 定义是这样描述的:它定义了算法家族,分别封装起来,让它们之间可以 ...

  4. Maven的pom.xml文件详解【转载】

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  5. Angular 2基础(一) 环境搭建

    Angular2是一款开源JavaScript库,由Google维护,用来创建页面应用程序.正式发布于2016年9月,基于ES6开发. 一.准备工作 使用Angular2开发,需要预先做一些配置上的配 ...

  6. ADB命令行控制界面开关

    以下命令需要root权限:   svc命令     这个脚本在/system/bin目录下,这个命令可以用来控制电源管理,wifi开关,数据开关(就是上网流量) svc power stayon [t ...

  7. [20171225]查看并行执行计划注意的问题.txt

    [20171225]查看并行执行计划注意的问题.txt --//如果使用dbms_xplan.display_cursor查看并行执行计划注意一些问题,通过例子说明: 1.环境: SCOTT@book ...

  8. [20171106]配置客户端连接注意.txt

    [20171106]配置客户端连接注意.txt --//在配置客户端连接时一般建议使用Net Manager工具,windows下调用执行Net Manager.--//linux下执行 netmgr ...

  9. webservice偶尔报黄页,解决方案

      在system.web节点里加以下代码 <webServices>      <protocols>        <add   name="HttpSoa ...

  10. Hive-1.2.1_06_累计报表查询

    1. 数据准备 # 本地数据准备 [yun@mini01 hive]$ pwd /app/software/hive [yun@mini01 hive]$ ll /app/software/hive/ ...