感觉没有错呀,初始化的问题也注意到了。。
#include<bits/stdc++.h>
using namespace std;
bool wd_in_mem[1005]; //每个单词是否在内存中, 0/1
int memory[105] = {-1};
int main()
{
int m, n, wd, cur = 0, cnt = 0;
cin>>m>>n;
for (int i = 0; i < n; i++) {
cin>>wd;
if (wd_in_mem[wd] == 0) { //内存中没有wd
//放入内存
wd_in_mem[wd] = 1; //内存中有wd了
if (memory[cur] != -1)
{
wd_in_mem[memory[cur]] = 0; //这个位置原来的数没有了
}
memory[cur] = wd;
cur++; //放置位后移
cur %= m;
cnt++; //查找次数加一
}
else continue;
}
cout<<cnt;
return 0;
}