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<k≤100) 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

 #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <set>
using namespace std;
int n,k,m;
set<char> good,bad,pr;
queue<char> q;
int main(){
scanf("%d",&n);
string s;
cin>>s;
for(int i=;i<s.length()-n+;i++){
char now=s[i];
int flag=;
for(int j=;j<n;j++){
if(s[i]!=s[j+i]){
good.insert(now);
flag=;
break;
}
}
if(flag==){
if(bad.find(now)!=bad.end())bad.erase(bad.find(now));
continue;
}
if(good.find(now)==good.end())bad.insert(now),i=i+n-;
}
for(int i=;i<s.length();i++){
if(bad.find(s[i])!=bad.end() && pr.find(s[i])==pr.end())printf("%c",s[i]),pr.insert(s[i]);
}
printf("\n");
for(int i=;i<s.length();i++){
if(bad.find(s[i])==bad.end())printf("%c",s[i]);
else{
printf("%c",s[i]);
i=i+n-;
}
}
}

注意点:看似简单,实际上还蛮复杂的。看了大佬的思路都是看重复的个数是不是n的倍数,再来判断。但总感觉都落下了一个考虑点,一开始认为是坏的,其实后面证明是好的,这个好像都没有考虑。

最新文章

  1. C语言字符串拷贝
  2. 图解Java内存回收机制
  3. 微软BI 之SSIS 系列 - 通过设置 CheckPoints 检查点来增强 SSIS Package 流程的重用性
  4. C#程序调用cmd执行命令
  5. RegexKitLite 使用详解
  6. 深入Spring之web.xml
  7. JavaScript学习笔记(七)——函数的定义与调用
  8. mfc100u.dll下载和使用方法
  9. 分享我在 vue 项目中关于 api 请求的一些实现及项目框架
  10. 关于UITabBarController的设置(iOS 开发)
  11. 记录小白实习生的HashMap源码 put元素 的学习和一些疑问
  12. Anaconda 使用指南
  13. NOIP需要掌握的内容(大致
  14. python&#160;以单例模式封装logging相关api实现日志打印类
  15. python测试开发django-33.admin后台一对一关系OneToOneField
  16. MySQL的DDL语句、DML语句与DCL语句
  17. ubuntu下IDEA配置tomcat报错Warning the selected directory is not a valid tomcat home
  18. POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]
  19. conv1d UpSampling1D aotoencoder 自编码代码摘录
  20. Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined

热门文章

  1. Java框架之Spring(三)
  2. java动态代理--一个简单的例子
  3. Spring表单验证(Spring Validation)
  4. PL/SQL 查询的数据出现乱码
  5. CSS| 框模型-margin
  6. Memory barrier 简介
  7. Android QMI机制
  8. python UDP套接字通信
  9. Python &amp; 机器学习之项目实践
  10. WCF REST模式下的UriTemplate路径问题