A1112. Stucked Keyboard
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的更多相关文章
- 【刷题-PAT】A1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- PAT A1112 Stucked Keyboard (20 分)——字符串
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...
- PAT甲级——A1112 Stucked Keyboard【20】
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...
- PAT_A1112#Stucked Keyboard
Source: PAT A1112 Stucked Keyboard (20 分) Description: On a broken keyboard, some of the keys are al ...
- 1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- PAT1112:Stucked Keyboard
1112. Stucked Keyboard (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...
- PAT 1112 Stucked Keyboard
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when yo ...
- PAT 1112 Stucked Keyboard[比较]
1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...
- PAT甲级——1112 Stucked Keyboard (字符串+stl)
此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078 1112 Stucked Keyboa ...
随机推荐
- hive条件过滤
where 过滤 %代表任意个字符,_代表一个字符; \\ 转移字符.\\_代表下划线
- git基本操作1
1.创建版本库 在文件夹下,打开Git Bash Here ,然后执行git init,文件夹中会多出.git文件夹.(.git可能是隐藏的) 2.创建a.txt vim a.txt ,并添加到版本 ...
- 对C#调用C++的dll的一点思考
最近在对接C++程序的时候碰到了一些问题,然后花了一段时间才解决,今天就这些小问题来做一个总结,很多时候由于对另外一种开发语言的不熟悉,会在使用的过程中遇到很多的问题,这些问题看似简单但是背后却有很多 ...
- 关于mysql远程登录问题
问题:mysql不能实现远程登录 前提:mysql开启了远程登录账号,安全组也放行了3306,防火墙是iptables,也加入了3306放行,但是还是不能实现远程访问 解决办法,使用iptables ...
- 吴恩达deeplearning之CNN—卷积神经网络
https://blog.csdn.net/ice_actor/article/details/78648780 个人理解: 卷积计算的过程其实是将原始的全连接换成了卷积全连接,每个kernel为对应 ...
- iPhone
电报交流***vpnpay app不能用了,只要能下载就可以用,谨慎卸载 升级.网络链接不成功的,多试几次,毕竟程序不会运行你的错误操作 ,重新添加链接服务器,继续搞!耐心的进行下面操作即可链接,如有 ...
- FTP登录不上 显示“找不到元素”
FTP登录不上 显示“找不到元素” 问题描述: 资源管理器登陆不上ftp服务器,ie现在打不开网页(包括普通的网页和ftp)360等其他浏览器可以正常打开网页. 解决方法: 应该是用了代理软件的问题, ...
- node.js 运行机制与简单使用
一.hello world 1.引入 required 模块 2.创建服务器 3.接收请求与响应请求 var http = require('http'); // 载入http模块 http.crea ...
- 一个有关FWT&FMT的东西
这篇文章在讲什么 相信大家都会FWT和FMT. 如果你不会,推荐你去看一下VFK的2015国家集训队论文. 设全集为\(U=\{1,2,\ldots,n\}\),假设我们关心的\(f_S\)中的集合\ ...
- 【XSY1591】卡片游戏 DP
题目描述 有标有数字为\(1\)~\(9\)的卡片各\(a_1,a_2\cdots a_9\)张,还有标有乘号的卡片\(m\)张.从中取出\(n\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...