1112 Stucked Keyboard

#include<iostream>

#include<map>

#include<set>

#include<string>

using namespace std;

bool sureNobroken256;

int main(){

int k,cnt=1;

cin>>k;//字符出现次数的阈值

string s;

cin>>s;

map<char,bool>m;//记录是否为坏键

set<char>printed;//记录已经输出的字符

char pre='#';

s=s+'#';

//第一次遍历,标记可能坏掉的键

for(int i=0;i<s.length();i++){

if(si==pre){

cnt++;

}else{

//如果连续出现的不是k的倍数,说明不是坏键

if(cnt%k!=0){

sureNobrokenpre=true;

}

cnt=1;

}

//如果当前出现的字符数是k的倍数,表示其为坏键

if(i!=s.length()-1){

ms\[i]=(cnt%k==0);

}

pre=si;//更新前一个字符

}

//第二次遍历,修正标记

for(int i=0;i<s.length()-1;i++){

if(sureNobrokens\[i]){

ms\[i]=false;

}

}

//输出所有坏键

for(int i=0;i<s.length()-1;i++){

if(ms\[i]&&printed.find(si)==printed.end()){

cout<<si;

printed.insert(si);

}

}

cout<<endl;

//输出修正后的字符

for(int i=0;i<s.length()-1;i++){

cout<<si;

if(ms\[i]){

i=i+k-1;

}

}

return 0;

}

相关推荐
JieE2121 天前
LeetCode 226. 翻转二叉树|JS 递归超详细拆解,二叉树入门经典题
javascript·算法
JieE2121 天前
LeetCode 104. 二叉树的最大深度|递归思路超详细拆解
javascript·算法
vivo互联网技术1 天前
CVPR 2026 | 全新强化学习框架 BeautyGRPO:重塑真实人像
算法·大模型·cvpr·影像
Darling噜啦啦1 天前
列表转树算法深度解析:从 Map 到 Reduce 的两种实现,面试高频考点
数据结构·算法·面试
clint4562 天前
C++进阶(1)——前景提要
c++
用户497863050732 天前
(一)小红的数组操作
算法·编程语言
夜悊2 天前
C++代码示例:进制数简单生成工具
c++
怕浪猫2 天前
Electron 系列文章封面图
算法·架构·前端框架
郝学胜_神的一滴2 天前
CMake 021: IF 条件判据详诠
c++·cmake