求教代码有什么问题,感觉问题不大但是过不去。。。(没学队列)
查看原帖
求教代码有什么问题,感觉问题不大但是过不去。。。(没学队列)
153533
one_leukocyte楼主2022/2/26 21:37
#include<bits/stdc++.h>
using namespace std;
int m,n,ans,t,l;//l为字典的长度 
int memory[110],word;
int main(){
cin>>m>>n;	
bool full=false,finden=false;
for(int i=0;i<n;i++){//输入单词循环 
	cin>>word;
	for(int j=0;j<=l;j++){//寻找单词循环 
		if(word==memory[j])//如果能找到 
			finden=true;//返回真 
	}
	if(!finden){//如果找不到 
		ans++;//从外字典中加入内存 
		if(!full){//如果内存未满 
			memory[l++]=word;//添加单词 
			t++;//当前位置加1 
			if(l==m-1)
				full=true;
		}
		else{//如果字典已满 
			t++;//开始顶替 
			memory[t%l]=word; 
		}
	}
	finden=false;//默认找不到 
}
cout<<ans<<endl;
return 0;
}
2022/2/26 21:37
加载中...