PAT甲级1112
来源:互联网 发布:淘宝首页 javascript 编辑:程序博客网 时间:2024/05/22 08:07
1112. Stucked Keyboard (20)
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:3caseee1__thiiis_iiisss_a_teeeeeestSample Output:
eicase1__this_isss_a_teest
#include<iostream>#include<string>#include<algorithm>#include<map>using namespace std;string s;int k;bool a[127] = { false };//asciimap<char, int> ma;int main(){cin >> k >> s;for (int i = 0; i < s.size(); i++){ma[s[i]]++;}map<char, int>::iterator it = ma.begin();for (it; it != ma.end(); it++){char c = it->first; int ccount = it->second;if (ccount%k != 0) a[c] = true;//not stuckedelse{int j = 0;while (j < s.size()){int count = 0;while(s[j] == c){j++; count++;}if (count&&count%k != 0) { a[c] = true; break; }else j++;}}}int i = 0;bool print[128] = { false };while(i<s.size()){if (a[s[i]] == false)//stucked{if (!print[s[i]]){cout << s[i];print[s[i]] = true;}s.replace(i, k - 1, "");}i++;}cout << endl << s;return 0;}
- 浙大PAT甲级 1112
- PAT甲级1112
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- PAT(甲级)1015
- vs2013新建类时自动添加头注释
- EDA软件_Cadence_Allegro 16.6添加封装库路径(导入网表时需要)
- ELK日志分析系统搭建
- 【B2B】三星点餐解决方案
- ReactiveCocoa信号使用方法
- PAT甲级1112
- Linux下MYSQL定时备份、定时清理几天前文件
- 2.14
- 深入浅出Android Support Annotations
- CC2640R2F低功耗无线MCU特性介绍
- 奇葩服务器切换root用户
- Java根据原图片获取缩略图
- 算法训练 s01串递归
- 【B2B】Smart Widget 解决方案