题目毁灭者.橙题篇.查字典
2025-08-18 16:45:55
发布于:浙江
3阅读
0回复
0点赞
太简单啦,模拟就好了,用两个变量做指针,一个指着在未满情况下当前要存储的一位,另一个指着实际上的第一个(类似循环队列的头指针)
#include<bits/stdc++.h>
using namespace std;
int a[5001];
int main(){
int m,n;
cin>>m>>n;
int o;
int s=0;
int top=1;
int ans=0;
for(int i=1;i<=n;i++){
cin>>o;
bool if_new=false;
for(int j=1;j<=s;j++){
if(a[j]==o){
if_new=true;
}
}
if(!if_new&&s>=m){
a[top]=o;
top++;
ans++;
}
if(!if_new&&s<m){
s++;
a[s]=o;
ans++;
}
}
cout<<ans;
return 0;
}
这里空空如也
有帮助,赞一个