#include<bits/stdc++.h>
using namespace std;
struct node{
int num;
bool alive=true;
struct node *next;
};
int kill(int the_num,struct node people[]){
//the_num-1是被叫到的人的位置
int the_kill=people[the_num-1].next->num;
people[the_num-1].next->alive=false;
people[the_num-1].next=people[the_num-1].next->next;
return the_kill;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m,i;
cin>>n>>m;
struct node people[n];
for(i=0;i<n-1;++i){
people[i].num=i+1;
people[i].next=&people[i+1];
}
people[n-1].num=n;
people[n-1].next=nullptr;
int the_num;
while(m--){
cin>>the_num; //num=the_num的位置在the_num-1
if(the_num>n) continue;
if(people[the_num-1].alive==false || people[the_num-1].next==nullptr) cout<<"0u0 ...... ?"<<'\n';
else cout<<kill(the_num,people)<<'\n';
}
return 0;
}
目前試17、18、19出現RE
如果說是因為超出陣列長度....我有試著改成宣告struct node people[n+100] 但沒效就是了(不知道是不是這樣修正啦哈哈)
望諸位指點迷津...謝謝大阿:)