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. MyBatis学习笔记(三) Configuration类

    一.初探Configuration类 我们先来看一下MyBatis的XML配置文件的结构,(摘自mybatis.org) 下面这个是Configuration类的部分变量 一点不一样是不是??? 其实 ...

  2. [转*译]Networking API Improvements in Windows 10

        在当今,以云优先,移动优先技术为宗旨的时代下,大多数Apps都至少有一些与web服务或网络上其他设备的集成.这些包括应用程序,它获取天气在线内容,新闻或体育比赛的分数,媒体或下载的播客,甚至对 ...

  3. web新手——新闻列表这样写不容易出错

    1.先写结构 a.如果列表没有时间   结构为:<li><a>新闻内容</a></li> b.如果列表有时间      结构为:<li>&l ...

  4. Archlinux/Manjaro使用笔记-安装配置搜狗输入法步骤

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.安装qtwebkit-bin软件包解决qtwebkit无法编译安装问题 aurman -S qtwebkit-bin 二.安 ...

  5. 网络安全之sql注入

    1.何为Sql注入? 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意的)SQ ...

  6. PHP 在WIN10 下配置

    apache: https://www.apachehaus.com/ php: https://windows.php.net/ https://windows.php.net/ 集成安装配置版:h ...

  7. sql: Query to Display Foreign Key Relationships and Name of the Constraint for Each Table in Database

    --20170505 --塗聚文 Geovin Du CREATE DATABASE DuMailSystem GO USE DuMailSystem GO --1查詢表的及备注说明 SELECT S ...

  8. window的cmd命令行下新增/删除文件夹及文件

    新增文件夹 (md / mkdir) md <folderName>: folderName 就是文件路径,只输入文件夹名称时表示在当前目录下创建文件夹. 比如:md F:\test\pr ...

  9. loj#2002. 「SDOI2017」序列计数(dp 矩阵乘法)

    题意 题目链接 Sol 质数的限制并没有什么卵用,直接容斥一下:答案 = 忽略质数总的方案 - 没有质数的方案 那么直接dp,设\(f[i][j]\)表示到第i个位置,当前和为j的方案数 \(f[i ...

  10. 常见聚类算法——K均值、凝聚层次聚类和DBSCAN比较

    聚类分析就仅根据在数据中发现的描述对象及其关系的信息,将数据对象分组(簇).其目标是,组内的对象相互之间是相似的,而不同组中的对象是不同的.组内相似性越大,组间差别越大,聚类就越好. 先介绍下聚类的不 ...