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 ...
随机推荐
- vue 项目使用 webpack 构建自动获取电脑ip地址
1.开发 H5 时移动端,经常会使用真机进行调试本地环境.webpack 配置服务器好多脚手架写的都是固定的,而在团队开发中需要每人配置自己的本机 ip 进行开发,每次开启开发环境的都需要修改,并且还 ...
- switch-case和if-else可互换时
当switch-case和if-else可互换时,应当优先采用switch-case.因为switch-case的效率更高(详情下回分解).
- Python rsa公私钥生成 rsa公钥加解密(分段加解密)-私钥加签验签实战
一般现在的SAAS服务提供现在的sdk或api对接服务都涉及到一个身份验证和数据加密的问题.一般现在普遍的做法就是配置使用非对称加密的方式来解决这个问题,你持有SAAS公司的公钥,SAAS公司持有你的 ...
- StatefulSet
StatefulSet: 1.稳点且唯一的网络标识符 2.稳点且持久的存储 3.有序.平滑的部署和扩展 4.有序.平滑的删除和终止 5.有序的滚动更新 三个组件组成:headless(无头服务) ...
- Python实现百度贴吧自动顶贴机
开发这款小工具,我们需要做一些准备: url.txt:多个需要顶起的帖子地址. reply:多条随机回复的内容. selenium:浏览器自动化测试框架 首先,我们先使用pip完成selenium的安 ...
- html5 服務器發送事件
html5允許頁面獲得來自服務器的更新. 單項消息傳送: 頁面獲得服務器的更新. 以前頁面也可以獲得服務器的更新,但必須詢問服務器是否有可用的更新,而服務器發送事件是單向自動發送. 使用服務器發送事件 ...
- k8s(一) kubeadm简单集群初始化
写给想入门kubernetes的同学们 # 系统版本 [root@master ~]# cat /etc/os-release NAME="CentOS Linux" VERSIO ...
- Spring MVC 使用介绍(二)—— DispatcherServlet
一.Hello World示例 1.引入依赖 <dependency> <groupId>javax.servlet</groupId> <artifactI ...
- C#使用读写锁解决多线程并发写入文件时线程同步的问题
读写锁是以 ReaderWriterLockSlim 对象作为锁管理资源的,不同的 ReaderWriterLockSlim 对象中锁定同一个文件也会被视为不同的锁进行管理,这种差异可能会再次导致文件 ...
- BZOJ1823[JSOI2010]满汉全席——2-SAT+tarjan缩点
题目描述 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的材料透过满族或是汉族的料理方式,呈现在數量繁多的菜色之中.由于菜色众多而繁杂,只有极少數博学多闻技艺高超的厨师能够做出满汉全席,而能够烹饪出经过 ...