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, ...
随机推荐
- 将日志(Microsoft.Extensions.Logging)添加到.NET Core控制台应用程序
在.NET Core项目中,日志记录是通过依赖项注入进行管理的. 尽管这对于ASP.NET项目效果很好,但在启动Startup.cs中的新项目时,所有这些都会自动创建,而在控制台应用程序中则需要一些配 ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 (B L )
B. Light bulbs 思路:差分 + 离散化, 好不容易懂了差分却没想到离散化,还是要罗老板出马..... AC代码: #include<bits/stdc++.h> using ...
- Django框架(十八)—— CBV源码分析、restful规范、restframework框架
目录 CBV源码分析.restful规范.restframework框架 一.CBV源码分析 1.url层的使用CBV 2.as_view方法 3.view方法 4.dispatch方法(可以在视图层 ...
- mysql 个人博客应用的建表和相关查询
一.建表 用户表tb_user create table if not exists tb_user( user_id int auto_increment, ) not null, user_pas ...
- python 自带http服务
python2: python -m SimpleHTTPServer python3: python3 -m http.server
- leetcode.矩阵.766托普里茨矩阵-Java
1. 具体题目 如果一个矩阵的每一方向由左上到右下的对角线上具有相同元素,那么这个矩阵是托普利茨矩阵.给定一个 M x N 的矩阵,当且仅当它是托普利茨矩阵时返回 True. 示例 1: 输入: ma ...
- Linux下设置Core文件生成路径及文件名
修改core dump文件路径: 方法1:临时修改: 修改/proc/sys/kernel/core_pattern文件/proc目录本身动态加载每次系统重启都会重新加载因此种方法只能作临时修改/p ...
- 17-vim-查找字符或单词-02-查找并替换
在vi中查找和替换命令需要在末行模式下执行. 命令 功能 :%s///g 末行模式下,查找并替换字符.例:%s /hello/world/g 1.全局替换 一次性替换文件中的所有文件的旧文本. 命令格 ...
- 【记录】centOS 搭建logstash +docker搭建elasticsearch伪集群+kibana链接集群elasticsearch节点
[注意]本文主要用于自我记录,注释较少. 安装logstash 1.上传logstash-6.4.3.tar.gz到服务中 2.tar –zxvf logstash-6.4.3.tar.gz 3.cd ...
- KiCAD泪滴
KiCAD泪滴 KiCAD没有自带的补泪滴功能,必须先下载一个插件,然后才能进行泪滴操作 链接 提取码:ey8o 1.下载泪滴插件,解压后将整个文件夹复制到目录 C:\Program Files\K ...