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<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int hashTB[];
int main(){
char str[], prt[] = {};
int N, K;
fill(hashTB, hashTB + , );
scanf("%d", &K);
scanf("%s", str);
N = strlen(str);
for(int i = ; i < N; i++){
int tag = ;
if(i + K > N){
hashTB[str[i]] = ;
continue;
}
for(int j = i; j < i + K; j++){
if(str[j] != str[i]){
hashTB[str[i]] = ;
tag = ;
break;
}
}
if(tag == ){
i += (K - );
}
}
int flag = ;
for(int i = ; i < N; i++){
if(hashTB[str[i]] == && prt[str[i]] == ){
printf("%c", str[i]);
prt[str[i]] = ;
flag = ;
}
}
if(flag == )
printf("\n");
for(int i = ; i < N; i++){
if(hashTB[str[i]] == ){
printf("%c", str[i]);
}else{
printf("%c", str[i]);
i += K - ;
}
}
cin >> N;
return ;
}

总结:

1、题意:给出一个字符串和粘连次数K,检查这个键是否是坏键。

2、使用哈希表。初始时假设所有键都是坏的,然后遍历,发现a没有粘连,则说明a是好的。 注意不能假设所有键是好的,然后发现坏件再设置为坏。因为aaaba,则会错误将a识别为坏件。

3、注意最后K个字符的判断。

A1112. Stucked Keyboard的更多相关文章

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

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

  2. PAT A1112 Stucked Keyboard (20 分)——字符串

    On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...

  3. 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. PAT_A1112#Stucked Keyboard

    Source: PAT A1112 Stucked Keyboard (20 分) Description: On a broken keyboard, some of the keys are al ...

  5. 1112 Stucked Keyboard (20 分)

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

  6. PAT1112:Stucked Keyboard

    1112. Stucked Keyboard (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...

  7. PAT 1112 Stucked Keyboard

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

  8. PAT 1112 Stucked Keyboard[比较]

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

  9. PAT甲级——1112 Stucked Keyboard (字符串+stl)

    此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078   1112 Stucked Keyboa ...

随机推荐

  1. 利用js给datalist或select动态添加option选项

    <!DOCTYPE html> <html> <head> <title>鼠标点击时加载</title> <script type=& ...

  2. 使用cmd命令删除文件夹下所有文件

    rmdir 删除整个目录 好比说我要删除 222 这个目录下的所有目录和档案,这语法就是: rmdir /s/q 222 其中: /s 是代表删除所有子目录跟其中的档案. /q 是不要它在删除档案或目 ...

  3. MRP设置自动执行

    1.在计划向导中,找到调度运算,如下配置, 2.配置成功后自动生成执行计划

  4. 本地数据访问时出现跨域问题Cross origin requests are only supported for protocol schemes: ……

    从桌面找到Chrome图标,右键属性,快捷方式,起始位置(安装路径) 注:在cmd中访问Program Files文件的方法 %ProgramFiles%=C:\Program Files %Prog ...

  5. Airflow 使用随笔(内含 TimeZone 和 Backfill 等的详解)

    其实怎么部署  airflow 又哪些特性,然后功能又是如何全面都可以在 Reference 的文章里面找到,都不是重点这里就不赘述了. 这里重点谈一下我在部署完成仔细阅读文档之后觉得可以总结的一些东 ...

  6. C#中那些常用的工具类(Utility Class)(一)

    代码越写越多,但是我们也需要经常去反思那些写过的代码,Utility Class就是这一类需要特别去反思总结的类,这些类像工具一样,我们经常通过一些静态方法,通过传入一些参数,然后得到我们需要的结果, ...

  7. Volatile的应用

    .java 的执行过程 Java代码在编译后会变成Java字节码 字节码被类加载器加载到JVM里 JVM执行字节码,转化为汇编指令在CPU上执行 Java中所使用的并发机制依赖于JVM的实现和CPU的 ...

  8. JS操作Cookies

    JS操作Cookies 获取Cookie function getCookie(c_name) { if (document.cookie.length > 0) { c_start = doc ...

  9. Codeforces Round #445 Div. 1

    A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...

  10. Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)

    直方图用于展示数据的分布情况,x轴是一个连续变量,y轴是该变量的频次. 下面利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://d ...