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. java-----Long转换为 int , string

    int: 1.调用intValue()方法 long ll = 300000; int ii= new Long(ll).intValue(); 2.先把long转换成字符串String,然后在转行成 ...

  2. JAVA jar命令(一)-jar打包class文件

    jar包本质上是将所有class文件.资源文件压缩打成一个包(也可以选择不压缩),可选择在jar包中生成META-INF/MANIFEST.MF文件,MANIFEST.MF是清单文件,里面可以记录主类 ...

  3. jQuery的两把利器

    1 jQuery核心函数 * 简称: jQuery函数($/jQuery) * jQuery库向外直接暴露的就是$/jQuery * 引入jQuery库后, 直接使用$即可 * 当函数用: $(xxx ...

  4. 暑期集训日志(Day6~Day17)

    章·十七:2019-07-28:为谁辛苦为谁甜 ·昨日小结 颓爆了QAQ,昨天又垫底了. 最简单一道题弃疗的我直接被甩倒了总榜垫底…… 我……不想说啥…… 我是渣比. 我不能颓废了. 醒来啊麦克白! ...

  5. Go的异常处理 defer, panic, recover

    Go语言追求简洁优雅,所以,Go语言不支持传统的 try…catch…finally 这种异常,因为Go语言的设计者们认为,将异常与控制结构混在一起会很容易使得代码变得混乱.因为开发者很容易滥用异常, ...

  6. 洛谷P1860——新魔法药水

    传送门:QAQQAQ 题意:商店里有N种药水,每种药水都有一个售价和回收价.小S攒了V元钱,还会M种魔法,可以把一些药水合成另一种药水.他一天可以使用K次魔法,问他一天最多赚多少钱? N<=60 ...

  7. n-map安装实操

    强烈建议大家从官网下载nmap,而不是其他的第三方.官网地址:https://nmap.org/download.html 打开是这样的,感觉有点阴森森的色调.BTW,谁能逃得过真香定律呢. wind ...

  8. Cookie自动管理

    如果想要对 cookies 干点什么就需要 HTTP Cookie 管理器了. 啥是 cookies 呢.储存在用户本地终端上的数据通常情况下,当用户结束浏览器会话 时,系统将终止所有的 Cookie ...

  9. Centos7解压.tar.bz2提示tar (child): bzip2: Cannot exec: No such file or directory解决方法

    Centos7解压.tar.bz2提示tar (child): bzip2: Cannot exec: No such file or directory解决方法 原因是因为该centos没有bzip ...

  10. arm-linux-readelf 的使用

    1. 读 elf 文件开始的文件头部 [arm@localhost gcc]$ arm­linux­readelf ­h hello ELF Header: Magic:   7f 45 4c 46 ...