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. Vue 系列之 样式相关

    Class 与 Style 绑定 动态修改元素样式 <head> <meta charset="utf-8" /> <meta http-equiv= ...

  2. scala简单入门_wordCount

    scala的语法写起来是非常的舒服的,相比java来说,简便许多.而Java在scala面前就显的略微有些笨重了. 接下来我们看一下scala版的wordcount import scala.io.S ...

  3. Jquery插件开发之图片放大镜效果(仿淘宝)

    原网转载地址:http://www.cnblogs.com/hnvvv/archive/2011/11/19/2255197.html 需求:公司某个网站,需要实现图片预览效果,并能像淘宝一样实现局部 ...

  4. 【代码笔记】Web-HTML-表单

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  5. Mobile first! Wijmo 5 + Ionic Framework之:费用跟踪 App

    费用跟踪应用采用了Wijmo5和Ionic Framework创建,目的是构建一个hybird app. 我们基于<Mobile first! Wijmo 5 + Ionic Framework ...

  6. 使用Twitter异常检测框架遇到的坑

    在Github上搜索“Anomaly Detection”,Twitter的异常检测框架(基于R语言)高居榜首,可见效果应该不错: 但是活跃度并不高,3-4年没人维护了: 因此在使用时难免会遇到一些坑 ...

  7. 《ASP.NET MVC企业实战》(一) MVC开发前奏

    一.工具和方法 学到了一些没用过的工具和方法: a)删除多余的using指令并排序:一个类头部的using一般会有很多用不到的,在完成类的编写后,可以右键选择”组织using”来删除没用的using并 ...

  8. angularjs的$http请求方式

    /*$http常用的几个参数 $http服务的设置对象: 1.method 字符串 表示发送的请求类型 get post jsonp等等 2.url 字符串 绝对或者相对的URL,请求的目标 3.pa ...

  9. Flutter 相机定制

    Flutter中与硬件相关的部分,一直都挺蛋疼的.方案基本上有两种,自己写,或者等出相关的库. 最近做的一个项目中,需要对相机做定制.有过相关模块开发经验的,就知道这种需求并不简单,况且是这种跨平台解 ...

  10. 记录C/C++中遇到的一些小问题

    1. printf 比如 char a = \x90; printf("%02x", a); 想输出为90,没想到却是ffffff90,这个问题害我一个程序老是出错 最终发现只要改 ...