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

注意点

  1. 是坏键的条件比较苛刻,只要某字符有一次重复出现的个数不是K的整数倍,那么此键就不是坏键。
  2. 输出坏键时同一个坏键只能输出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】的更多相关文章

  1. PAT甲级——1112 Stucked Keyboard (字符串+stl)

    此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078   1112 Stucked Keyboa ...

  2. 【刷题-PAT】A1112 Stucked Keyboard (20 分)

    1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...

  3. PAT 甲级 1112 Stucked Keyboard

    https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...

  4. PAT甲级 1112 Stucked Keyboard

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 这道题初次写的时候,思路也就是考虑 ...

  5. PAT A1112 Stucked Keyboard (20 分)——字符串

    On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...

  6. 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)

    题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...

  7. PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)

    题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...

  8. PAT (Advanced Level) 1112. Stucked Keyboard (20)

    找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...

  9. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

随机推荐

  1. Vue for循环 例子

    demo <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf- ...

  2. 43. 守护线程 和 join方法

    1.守护线程(后台线程):            我们在使用一款软件的时候,有的软件会让我们在不知道的情况下下载一些东西,那么这个就是后台线程.            一般用于提高软件的下载量(也就是 ...

  3. jenkins的安装和启用

    1.下载Jenkins:下载地址:https://jenkins.io/zh/download/ 2.将Jenkins.war包上传到Tomcat的webapps目录下,本次的目录是/usr/loca ...

  4. sublime快捷键汇总

    Sublime Text 3 快捷键精华版 Ctrl+Shift+P:打开命令面板Ctrl+P:搜索项目中的文件Ctrl+G:跳转到第几行Ctrl+W:关闭当前打开文件Ctrl+Shift+W:关闭所 ...

  5. 阿里云成为Hyperledger超级账本全球会员,发力区块链生态建设

    摘要: 阿里云将会与Hyperledger社区共同推进全球区块链技术和商业生态在多行业领域的建设. 2018年12月12日在瑞士巴塞尔的2018Hyperledger全球峰会上,阿里云正式加入Hype ...

  6. Python Django主机管理

    1.新建一个django project项目 django-admin startproject DjangoWeb 2.新建app python manage.py startapp master ...

  7. NX二次开发-UFUN将目录与文件名组合在一起uc4575

    NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_cfi.h> UF_initialize() ...

  8. EnhanceFunc__增强函数集

    想将经常用到的功能函数写在一起,花时间精心维护,然后以后就用起来就舒服很多了 目前就写了进程调试权限,远程线程注入,远程线程释放这三个函数.还有很多功能,以后慢慢加 // last code by g ...

  9. 6、 restful API

    RESTful 一种软件架构风格.设计风格,而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制. RE ...

  10. 使用Pyppeteer进行gmail模拟登录

    import asyncio import time from pyppeteer import launch async def gmailLogin(username, password, url ...