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;

}

相关推荐
console.log('npc')1 小时前
Python 学习教程 · 第4课:数据结构
数据结构·python·学习
eggwyw2 小时前
C++设计模式之解释器模式
开发语言·c++
橘子133 小时前
【高级数据库】关系代数基本概念
算法
电科_银尘14 小时前
【大模型算法与工程 15】手写Self-Attention:Q、K、V与缩放点积
算法
我不会插花弄玉15 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴17 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
秋天的怀念_David17 小时前
算法一千零一夜 · 第三十三夜 · 跳表
java·程序人生·算法
西西弗Sisyphus18 小时前
C++ explicit 关键字工程实践
开发语言·c++
Pniubi20 小时前
力扣21合并两个有序链表
算法·leetcode·职场和发展
AIgorithmGEEK20 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set