请接收
2024-11-02 11:28:51
发布于:广东
46阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,m;
char q[1001];
int hh,tt;//队首,队尾
//判断字符在不在队列中
bool check(char c){
for(int i=hh+1;i<=tt;i++){//遍历
if(q[i]==c) return true;//在队列中
}
return false;//不在队列中
}
int main(){
cin>>n>>m;
int ans=0;
for(int i=0;i<n;i++){
char c;
cin>>c;//输入n个字符
if(check(c)==false){//字符没在队列中
ans++;
q[++tt]=c;//入队
if(tt-hh>m) hh++;//如果队列元素大于m,出队
}
}
cout<<ans;
return 0;
}
这里空空如也
有帮助,赞一个