PAT 甲级 1112 Stucked Keyboard
https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960
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
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ; int k;
string s; map<char, int> mp, out; struct X {
char sign;
int cnt;
}q[maxn];
int sz; int main() {
cin >> k >> s; int len = s.length(); char Sign = s[];
int Cnt = ; for(int i = ; i < len; i ++) {
if(s[i] == Sign) {
Cnt ++;
} else {
q[sz].sign = Sign;
q[sz].cnt = Cnt;
sz ++; Sign = s[i];
Cnt = ;
}
} q[sz].sign = Sign;
q[sz].cnt = Cnt;
sz ++; /*for(int i = 0; i < sz; i ++) {
cout << q[i].sign << " " << q[i].cnt << endl;
}*/ for(int i = ; i < sz; i ++) {
if(q[i].cnt % k != ) mp[q[i].sign] = ;
} for(int i = ; i < sz; i ++) {
if(mp[q[i].sign] == && out[q[i].sign] == ) {
cout << q[i].sign;
out[q[i].sign] = ;
}
}
cout << endl; for(int i = ; i < sz; i ++) {
int num = q[i].cnt;
if(mp[q[i].sign] == ) num = num / k;
while(num --) cout << q[i].sign;
}
cout << endl; return ;
}
之前自己写了一个 18 的因为没有考虑 sss_s 的情况 这样的情况 s 是不卡的键 所以用 q 记下每一段重复的字符以及出现次数然后再输出答案
(这个是我 wa 掉的代码)
20 分的题目能被我写成这个样子真滴想抽自己了 我是猪吧
#include <bits/stdc++.h>
using namespace std; int N;
string s;
map<char, int> mp;
map<char, int> vis; int main() {
scanf("%d", &N);
cin >> s;
int len = s.length();
mp.clear(); vis.clear(); string ans = "";
string out = "";
for(int i = ; i < len;) {
char temp = s[i];
int cnt = ;
if(mp[temp]) {
out += temp;
i ++;
continue;
}
for(int j = i; j < len; j ++) {
if(s[j] == temp) cnt ++;
else break;
} if(cnt % N == ) {
if(vis[temp] == ) {
ans += temp;
vis[temp] = ;
}
for(int j = ; j < cnt / N; j ++)
out += s[i]; i += cnt;
} else {
mp[s[i]] = ;
out += s[i];
i ++;
}
} cout << ans << endl << out << endl;
return ;
}
PAT 甲级 1112 Stucked Keyboard的更多相关文章
- PAT甲级——1112 Stucked Keyboard (字符串+stl)
此文章同步发布在我的CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90041078 1112 Stucked Keyboa ...
- PAT甲级 1112 Stucked Keyboard
题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 这道题初次写的时候,思路也就是考虑 ...
- PAT甲级——A1112 Stucked Keyboard【20】
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the char ...
- PAT 1112 Stucked Keyboard
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when yo ...
- PAT 1112 Stucked Keyboard[比较]
1112 Stucked Keyboard(20 分) On a broken keyboard, some of the keys are always stucked. So when you t ...
- 1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- 【刷题-PAT】A1112 Stucked Keyboard (20 分)
1112 Stucked Keyboard (20 分) On a broken keyboard, some of the keys are always stucked. So when you ...
- 【PAT甲级】1112 Stucked Keyboard (20分)(字符串)
题意: 输入一个正整数K(1<K<=100),接着输入一行字符串由小写字母,数字和下划线组成.如果一个字符它每次出现必定连续出现K个,它可能是坏键,找到坏键按照它们出现的顺序输出(相同坏键 ...
- PAT甲题题解-1112. Stucked Keyboard (20)-(map应用)
题意:给定一个k,键盘里有些键盘卡住了,按一次会打出k次,要求找出可能的坏键,按发现的顺序输出,并且输出正确的字符串顺序. map<char,int>用来标记一个键是否为坏键,一开始的时候 ...
随机推荐
- This assembly may have been downloaded from the Web. ......
错误消息例如: Error 6 Could not load the assembly file:///D:\me\Projects\DLL\Newtonsoft.Json\Portable40\Ne ...
- 20145234黄斐《网络对抗技术》实验九、Web安全基础实践
PS:我是分了两次做的这次试验,第二次实验的时候电脑出了一点问题熄火了……原本后面的是有图的结果博客没保存图没了…… WebGoat WebGoat是由著名的OWASP负责维护的一个漏洞百出的J2EE ...
- UOJ UR#9 App管理器
题目传送门 题目大意大概就是给你一个混合图(既有有向边又有无向边),对于每条无向边,u-v,问删去u->v,或删去v->u那条可以使新图强连通.(保证数据有解). 这道题前几个数据点送分. ...
- RMAN中建立Catalog 用数据库的例子
RMAN中可以备份metadata到control文件,也可以备份metadata到数据库中,此数据库称为catalog database. 本文参考网上文章,建立一个例子: 使用机器: 机器1:ta ...
- 10.14 (上午)开课一个月零十天 (PHP环境搭建)
一.修改APACHE的监听端口 2 1.在界面中选apache,弹出隐藏菜单选项,打开配置文件httpd.conf; 2.找到Listen 80 和 ServerName localhost:80; ...
- CSS快速入门-实用技巧
1.整体布局 大部分的布局都是由三部分组成,header.body.footer. 代码布局:写三个div <!DOCTYPE html> <html lang="en&q ...
- Python 从零搭建 Conf_Web 配置管理平台
作者:Eagle 某船舶行业科技公司,运维工程师,51Reboot学员.通过在51Reboot学习,由运维工程师转至运维开发工程师.完成公司自动化平台的构建,对运维开发有了自己的理解,空闲时间写了这么 ...
- linux for 循环的小应用
[root@localhost ~]# mkdir -pv /home/data{1..5} # 创建多个目录 以下两种方法类似. for i in {1..5};do echo "&l ...
- Ubuntu下LimeSDR Mini使用说明
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 LimeSDR链接:https://item.taobao.com/item.htm?spm=a230r.1 ...
- [朴孝敏][Sketch]
歌词来源:http://music.163.com/#/song?id=406907303 作曲 : Ryan S. Jhun/August Rigo/Denzil Remedios [作曲 : Ry ...