解题
2026-03-25 17:47:29
发布于:江苏
5阅读
0回复
0点赞
这个是使用队列实现的,并且使用自己编的函数实现的,如果需要,可以换成系统自带的库里的,如有bug,欢迎评论
#include <bits/stdc++.h>
using namespace std;
int tail = 0,head = 0,n,m,cnt = 0;
char a[10000] = {},st[10000] = {};
void push(char x){
tail++;
st[tail] = x;
}
void pop(){
head++;
}
int size(){
return tail-head;
}
bool f(char x){
for(int i = head+1;i<=tail;i++){
if(x == st[i]){
return false;
}
}
return true;
}
int main(){
cin>>n>>m;
for(int i = 0;i<n;i++){
cin>>a[i];
}
for(int i = 0;i<n;i++){
if(f(a[i])){
if(size()>=m){
pop();
}
push(a[i]);
cnt++;
}
}
cout<<cnt;
return 0;
}
这里空空如也


有帮助,赞一个