PAT_A1112#Stucked Keyboard
Source:
Description:
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 teeeeeestwe know that the keysiandemight be stucked, butsis not even though it appears repeatedly sometimes. The original string could bethis isss a teest.
Input Specification:
Each input file contains one test case. For each case, the 1st line gives a positive integer k (1) 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
Keys:
Code:
/*
Data: 2019-07-19 18:45:30
Problem: PAT_A1112#Stucked Keyboard
AC: 29:33 题目大意:
键盘上坏掉的键会重复打印K次,给出结果字符串,找出坏掉的键和原始字符串
输入:
第一行给出,重复次数k
第二行给出,结果字符串
输出:
坏掉的字符
原始字符串
*/ #include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
char mp[]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int k;
scanf("%d", &k);
string s,brk="";
cin >> s;
for(int i=; i<s.size(); i++)
{
int cnt=;
while(i+<s.size() && s[i]==s[i+]){
i++;cnt++;
}
if((cnt+)%k== && mp[s[i]]==)
mp[s[i]]=;
else if((cnt+)%k!=)
mp[s[i]]=;
}
for(int i=; i<s.size(); i++){
if(mp[s[i]]== || mp[s[i]]==)
{
if(mp[s[i]]==){
brk += s.substr(i,);
mp[s[i]]=;
}
s.erase(i,k-);
}
}
cout << brk << endl;
cout << s << endl; return ;
}
PAT_A1112#Stucked Keyboard的更多相关文章
- 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 ...
- 1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- 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 ...
- 【刷题-PAT】A1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- A1112. Stucked Keyboard
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 甲级 1112 Stucked Keyboard
https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...
随机推荐
- JSP 取list的长度
引入:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> L ...
- hci_ceph安装过程
auto loiface lo inet loopbackauto enp50s0f0iface enp50s0f0 inet static address 192.168.1.6 netmask 2 ...
- Windows-右键菜单添加选项
新建 add.reg 输入选项名和选项对应程序路径 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\选项名] [HKEY ...
- NMS python实现
import numpy as np ''' 目标检测中常用到NMS,在faster R-CNN中,每一个bounding box都有一个打分,NMS实现逻辑是: 1,按打分最高到最低将BBox排序 ...
- 数据库(二)—— MySQL索引优化
目录 MySQL的索引优化 一.MySQL 5.7的初始化配置 二.MySQL配置文件 1.配置 2.配置文件作用 三.多实例 1.创建相关的目录 2.创建实例的配置文件 3.初始化 4.授权 5.启 ...
- Java学习第一次总结
在此之前我需要声明一下,我不载过多的评论知识点的简单与难易程度.写出来只是为了方便使用,现阶段追求的是实在.㈠①自动类型转换由低到高byte.short.char→int→long→flot→doub ...
- jquery 条件搜索某个标签下的子标签
$("li[name='"+name+"']").find("a[value='" + value + "']").pa ...
- python调用tushare获取沪深股通十大成交股
接口:hsgt_top10 描述:获取沪股通.深股通每日前十大成交详细数据 注:tushare库下载和初始化教程,请查阅我之前的文章 输入参数 名称 | 类型 | ...
- 使用Nuget重新安装packages.config中的组件的方法
Update-Package -ProjectName 'Ko.app.web' -Reinstall 该语句作用:按照packages.config中给出的程序组件,重新下载安装一遍.
- centos6系列更换阿里yum源
1.首先备份原来的cent os官方yum源 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 2. ...