Source:

PAT A1112 Stucked Keyboard (20 分)

Description:

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

Keys:

Code:

 /*
Data: 2019-07-19 18:45:30
Problem: PAT_A1112#Stucked Keyboard
AC: 29:33 题目大意:
键盘上坏掉的键会重复打印K次,给出结果字符串,找出坏掉的键和原始字符串
输入:
第一行给出,重复次数k
第二行给出,结果字符串
输出:
坏掉的字符
原始字符串
*/ #include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
char mp[]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int k;
scanf("%d", &k);
string s,brk="";
cin >> s;
for(int i=; i<s.size(); i++)
{
int cnt=;
while(i+<s.size() && s[i]==s[i+]){
i++;cnt++;
}
if((cnt+)%k== && mp[s[i]]==)
mp[s[i]]=;
else if((cnt+)%k!=)
mp[s[i]]=;
}
for(int i=; i<s.size(); i++){
if(mp[s[i]]== || mp[s[i]]==)
{
if(mp[s[i]]==){
brk += s.substr(i,);
mp[s[i]]=;
}
s.erase(i,k-);
}
}
cout << brk << endl;
cout << s << endl; return ;
}

最新文章

  1. Mac下安装Matlab R2015b
  2. 在Sharepoint 2013中,使用JS判断当前用户是否在某个组里面
  3. 【转】CSS3动画帧数科学计算法
  4. hibernate进行多表联合查询
  5. SQL——神奇代码1之Update
  6. phantomjs 乱码解决
  7. 刀哥多线程笔记之gcd-02-block
  8. stl的实现原理简单讲解,通熟易懂
  9. ZOJ Problem Set - 1002(DFS)
  10. iOS学习之应用之间的操作(转发)
  11. VS2012 TFS解决离职后代码遗留未迁入问题
  12. Mysql官方文档翻译系列-7.3.1 Establishing a Backup Policy
  13. JSTL之forEach的使用详解(简单的技术说得很详细)
  14. 移动设备分辨率(终于弄懂了为什么移动端设计稿总是640px和750px)
  15. django ajax 及批量插入数据 分页器
  16. 第十三节: EF的三种模式(三) 之 来自数据库的CodeFirst模式
  17. &#39;假定以下程序经编译和连接后生成可执行文件PROG.EXE,如果在此可执行文件所在目录的DOS提示符下键入:PROG ABCDEFGH IJKL&lt;回车&gt;,则输出结果为( ). void main( int argc, char *argv[]) { while(--argc&gt;0) cout&lt;&lt;argv[argc]; cout&lt;&lt;&quot;\n&quot;; }
  18. cordova 问题汇总
  19. Activity声明周期1
  20. Android学习之基础知识五—ListView控件(最常用和最难用的控件)

热门文章

  1. STM32 系统架构
  2. HTML5: HTML5 Geolocation(地理定位)
  3. 查看.Net Framework的版本(PC和WinCE)
  4. Rust &lt;0&gt;:源代码组织,Cargo 入门
  5. html-body标签中相关标签 02
  6. USACO Milk Routing /// 优先队列广搜
  7. Pytest -断言、跳过及运行
  8. 一、最新Kafka单节点部署+测试 完整
  9. 2018-8-29-Roslyn-静态分析
  10. 我的黑苹果之路 9400f + msi b360 mortar + 1050ti