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:

3
caseee1__thiiis_iiisss_a_teeeeeest

Sample Output:

ei
case1__this_isss_a_teest

分析:字符串题,卡了好久,最后发现样例中的3是输入的数n。。要细心啊!

写的比较复杂,思路如下:

1、建立一个map<char,int>型,先遍历一次,记录每个字母如果重复出现n次,则让该字母所映射的数加n

2、再遍历一次,如果某个char映射的数不为0,那么看他后面n-1位是否相同,如果不相同,则把该数置为0,相当于删除这个“坏键”。

3、输出坏键,注意到按输入顺序输出,并且只能输出一次,这里又建了一个map,代表是否输出过了。如果用set会排序输出,突然想到unordered_set不知道是否也可以,没试过。

4、再按要求输出字符串即可。

复杂度O(len*n),其中len为字符串长度,n为重复次数
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-27-13.17.44
 * Description : A1112
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 #include<unordered_map>
 using namespace std;
 unordered_map<char,int> mp;
 unordered_map<char,bool> isPrinted;
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n,len;
     string ori,ans;
     cin>>n>>ori;
     len = ori.length();
     ;i<len;i++){
         int j;
         ;j<i+n;j++){
             if(ori[i]!=ori[j]){
                 break;
             }
         }
         if(j==n+i){
             mp[ori[i]]+=n;
             i+=n-;
         }
     }
 //    for(int i=0;i<len;i++){
 //        if(mp[ori[i]] % n!=0){
 //            mp[ori[i]]=0;
 //        }
 //    }
     ;i<len;i++){
         ){
             int j;
             ;j<i+n;j++){
                 if(ori[i]!=ori[j]){
                     mp[ori[i]]=;
                     break;
                 }
             }
             ;
         }
     }
     ;i<len;i++){
          &&isPrinted[ori[i]]==false){
             cout<<ori[i];
             isPrinted[ori[i]]=true;
         }
     }
     cout<<endl;
     ;i<len;i++){
         ){
             cout<<ori[i];
             i+=n-;
         }
         else cout<<ori[i];
     }
     ;
 }
 
 

1112 Stucked Keyboard (20 分)的更多相关文章

  1. 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)

    题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...

  2. PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)

    题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...

  3. PAT (Advanced Level) 1112. Stucked Keyboard (20)

    找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...

  4. PAT 1112 Stucked Keyboard

    1112 Stucked Keyboard (20 分)   On a broken keyboard, some of the keys are always stucked. So when yo ...

  5. PAT甲级——1112 Stucked Keyboard (字符串+stl)

    此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078   1112 Stucked Keyboa ...

  6. PAT 1112 Stucked Keyboard[比较]

    1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...

  7. PAT 甲级 1112 Stucked Keyboard

    https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...

  8. 1112 Stucked Keyboard

    题意:坏掉的键若被按下,总是重复打出k次.比如,k为3,打出的序列如下—— thiiis iiisss a teeeeeest 坏掉的键是i和e,虽然iiisss中s也出现了3次,但它不是坏掉的键,因 ...

  9. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

随机推荐

  1. DevExpress v17.2新版亮点—.NET Reporting篇(一)

    用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了.NET Reporting v17.2 的新功能,快来下载试用新版本! All ...

  2. BigPipe 大的页面分割成一个一个管道

    bigpipe创新驱动力  node实现 具体实现 过去十年,现代web站点变得更加动态和内容化,交互性也逐步增强, 传统的页面处理的方式却没有保持一样的速度发展,越来越不能满足用户对极致性能的追求. ...

  3. C#实现Access导入导出Excel

    一.Access从Excel中导入数据 .用到的Excel表的格式及内容 实现 [c-sharp] view plaincopyprint? OleDbConnection con = new Ole ...

  4. python两个子线程通过queue通信

    SocketServer端代码 #!/usr/bin/env python import threading import SocketServer import time import queue ...

  5. NBUT 1217 Dinner 2010辽宁省赛

    Time limit  1000 ms Memory limit  32768 kB Little A is one member of ACM team. He had just won the g ...

  6. 分析苹果代充产业链 汇率差+退款造就三线城市千万富翁‍_中新游戏研究_Joynews中新游戏

    分析苹果代充产业链 汇率差+退款造就三线城市千万富翁‍_中新游戏研究_Joynews中新游戏 CNG:近日有媒体曝出8月22日这一天,有一家淘宝店卖出了351张面值4000南非南特的App Store ...

  7. google-protobuf安装详解

    前言 编译调试项目的过程中涉及到caffe的编译,提示没有安装protobuf的错误,本文详解protobuf的安装: 问题描述 解决步骤 1.查看google protobuf的github,没有直 ...

  8. 电脑技巧合集 - imsoft.cnblogs

    ● 如何制作网页● 教你建一个别人打不开的文件夹 ● 只改一个值!马上加快宽带上网速度 ● 在电脑右下角显示你的名字● XP系统如何加快开机速度● 连接宽带时出错表示的意思 ● 恢复丢失数据的方法● ...

  9. Spring MVC 学习)——控制器与@RequestMapping详解

    Spring MVC 学习总结(二)——控制器定义与@RequestMapping详解 一.控制器定义 控制器提供访问应用程序的行为,通常通过服务接口定义或注解定义两种方法实现. 控制器解析用户的请求 ...

  10. java设计模——反射的应用 (利用反射来去除if判断语句)

    利用反射来去除if判断语句 我的以前写的一个查分系统,就是部长让我写的那个,使用一个分发器(函数),他会根据传递进来的字符串参数调用不同的方. If(“add”.equalsIgnoreCase(fu ...