PAT甲级——A1112 Stucked Keyboard【20】
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) 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
注意点
- 是坏键的条件比较苛刻,只要某字符有一次重复出现的个数不是K的整数倍,那么此键就不是坏键。
- 输出坏键时同一个坏键只能输出1次,且需按在字符串input中出现的顺序进行输出。
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str, res = "", bad = "", temp = "";
int key[] = { };
cin >> n;
getchar();
getline(cin, str);
for (int i = ; i < str.length();)
{
int j = i + ;
while (j < str.length() && str[j] == str[i])//重复字符
++j;
if (key[str[i]] >= )//不是坏键
key[str[i]] = (j - i) % n == ? : -;//重复n次是坏键
i = j;
}
bool out[] = { false };//表示是否输出过
for (int i = ; i < str.length();)
{
res += str[i];
if (key[str[i]] == )//为坏键
{
if (out[str[i]] == false)//还为输出过
bad += str[i];
out[str[i]] = true;//输出过
i += n;//跳过重复键
}
else
++i;//继续遍历
}
cout << bad << endl << res << endl;
return ;
}
PAT甲级——A1112 Stucked Keyboard【20】的更多相关文章
- 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 ...
- PAT 甲级 1112 Stucked Keyboard
https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...
- PAT甲级 1112 Stucked Keyboard
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 这道题初次写的时候,思路也就是考虑 ...
- 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 (20分)(字符串)
题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...
- PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)
题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...
- PAT (Advanced Level) 1112. Stucked Keyboard (20)
找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
随机推荐
- loj2000[SDOI2017]数字表格
题意:f为Fibnacci数列.求$\prod_{1<=i<=n,1<=j<=m} f[gcd(i,j)]$. n,m<=1e6. 标程: #include<bit ...
- MySql 字段类型对应 Java 实体类型
前言 MySQL Connector/J 对于 MySql 数据类型和 Java 数据类型之间的转换是很灵活的: 一般来讲,任何 MySql 数据类型都可以被转换为一个 java.lang.Strin ...
- delphi Copy函数 和 Pos函数
copy(a,b,c); a:就是copy源,就是一个字符串,表示你将要从a里copy一些东西, b:从a中的第b位开始copy(包含第1位), c:copy从第b位开始后的c个字符, 例如: m:= ...
- thinkphp 标签库驱动
任何一个模板引擎的功能都不可能是为你量身定制的,具有一个良好的可扩展机制也是模板引擎的另外一个考量,Smarty采用的是插件方法来实现扩展,Think\Template由于采用了标签库技术,比Smar ...
- NX二次开发-设置WCS显示UF_CSYS_set_wcs_display
NX9+VS2012 #include <uf.h> #include <uf_csys.h> UF_initialize(); //设置WCS显示 //1显示WCS, 0不显 ...
- NX二次开发-UFUN按类选择对话框UF_UI_select_with_class_dialog
#include <uf.h> #include <uf_ui.h> UF_initialize(); //按类选择对话框 char sCue[] = "按类选择对话 ...
- NX二次开发-UFUN创建B面UF_MODL_create_bsurf
NX9+VS2012 #include <uf.h> #include <uf_modl.h> //创建一个B面 ;//U方向极数 ;//V方向极数 ;//U方向规则 ;//V ...
- 3.RabbitMQ 第一个程序
RabbitMQ消息服务器主要解决应用程序之间异步消息传输问题,传统的MQ分为点对点和主题与订阅,RabbitMQ使用Exchange(交换机)实现更加灵活的消息传递. 前面介绍过几个概念,Routi ...
- 使用Docker创建数据容器
使用Docker创建数据容器 翻译自: Data-only container madness 1.什么是数据容器? 数据容器就是本身只创建一个volume供其他容器共享,创建完后即退出,不执行任何任 ...
- OSI七层网络模型分别是哪七层?各运行那些协议?
本文摘自:https://blog.csdn.net/JeremyZJM/article/details/78184775 应用层 DHCP · DNS · FTP · Gopher · HTTP · ...