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 teeeeeest
we know that the keysi
ande
might be stucked, buts
is 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, ...
随机推荐
- mysql定时任务(数据库管理工具and 纯命令行)
1.工具:Navicat 2.通过下列语句l爱查询event是否开启 打开Navicat命令列界面(点击工具可以看到或按F6) 输入下面命令 show variables like '%sche%'; ...
- 2019牛客多校第⑨场E All men are brothers(并查集+组合数学)
原题:https://ac.nowcoder.com/acm/contest/889/E 思路: 做并查集,维护每个集合大小,初始化操作前的总方案数,每次合并两个集合时减少的数量=合并的两个集合大小相 ...
- PAT_A1100#Mars Numbers
Source: PAT A1100 Mars Numbers (20 分) Description: People on Mars count their numbers with base 13: ...
- 08、python的基础--->文件操作
注:用btyes方式的一般都是在“非文字类的(比如图片)” 1.文件的读取 >>>第1种 #绝对路径 s = open('E:\天气.txt', mode='r', encoding ...
- vue做一个上移和下移,删除的li 功能
效果图: 思路就是冒泡原理,把数据放到一个空数组,对其进行排序, 单选框用到的是iview . 具体实现代码: <div v-for="item in singledLists&quo ...
- ES5新增方法(数组,字符串,对象)
一.数组方法 迭代(遍历)方法:forEach().map().filter().some().every(): 1. array. forEach(function(value,index,arr) ...
- 【转载】vue install报错run `npm audit fix` to fix them, or `npm audit` for details html
原链接https://www.jianshu.com/p/60591cfc6952 执行npm install 出现如下提醒 added 253 packages from 162 contribut ...
- 从零开始搭建系统2.8——HDFS安装及配置
从零开始搭建系统2.8——HDFS安装及配置
- docker build 时 alpine 无法安装软件问题的解决
使用 alpine 作为 docker 基础镜像时,运行 apk add ..... 遇到如下错误: WARNING: Ignoring http://dl-cdn.alpinelinux.org/a ...
- ICPC2008哈尔滨-E-Gauss Elimination
题目描述 Li Zhixiang have already been in “Friendship” ocean-going freighter for three months. The excit ...