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. 使用 SpringBoot 配置发送邮件功能

    1.使用 SpringBoot 配置发送邮件功能 项目总体结构 用户表设计 SET FOREIGN_KEY_CHECKS=0; CREATE DATABASE sample; USE sample; ...

  2. Can't finish GitHub sharing process Successfully created project 'springcloud-parent' on GitHub,

    解决Can't finish GitHub sharing process Successfully created project '' on GitHub, but initial push fa ...

  3. 线程池 一 ForkJoinPool

    java.util.concurrent public class ForkJoinPool extends AbstractExecutorService public abstract class ...

  4. 用jQuery实现鼠标移动切换图片动画

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. NTT数论变换

    数论变换NTT 前置知识 FFT:NTT的思想和FFT一样(FFT介绍) 概述 数论变换,即NTT(Number Theory Transformation?),是基于数论域的FFT,一般我们默认FF ...

  6. Tomcat debug 模式, Application一直reload,导致内存溢出

    在server.xml配置文件中,将reloable改为false.

  7. [转] 如何在vps上安装和登录Xwindows

    如何VPS也可以拥有像windows一样图形窗口,这里写个教程,据说xwindows是一个比微软windows还强大的linux图形界面,怎样强大,我也是听说的,你可以自己去试,然后告诉我. vps安 ...

  8. UVA 12676 Inverting Huffman

    题目链接:https://vjudge.net/problem/UVA-12676 题目大意 一串文本中包含 N 个不同字母,经过哈夫曼编码后,得到这 N 个字母的相应编码长度,求文本的最短可能长度. ...

  9. 解决:Map的area属性标签鼠标Hover可以给area加背景

    css的area标签是不支持hover的,只有a标签才支持.li标签在IE浏览器下才支持,所以采用jquery的mouseenter和mouseleave事件完成.首先讲jQuery对应的事件:1.m ...

  10. 普通用户授予root权限

    开始用linux的时候会遇到用户权限问题,比如安装软件的时候经常会提示权限不足,下面介绍给普通用户授予root权限. 找到  cd /etc/sudoers可以看到用户的权限是:只有读取的权限(以下操 ...