标签:begin ios span iostream i++ erase pre color 双向链表
1 #include<iostream> 2 #include<list> 3 using namespace std; 4 int main(){ 5 int t,n; 6 cin>>t; 7 while(t--){ 8 cin>>n; 9 int k=2; 10 list<int>mylist; 11 list<int>::iterator it; 12 for(int i=1;i<=n;i++) 13 mylist.push_back(i); //赋值,最后输出原始编号 14 while(mylist.size()>3){ 15 int num=1; 16 for(it=mylist.begin();it!=mylist.end();){ 17 if(num++%k==0) 18 it=mylist.erase(it); 19 else it++; 20 } 21 k==2?k=3:k=2; 22 } 23 for(it=mylist.begin();it!=mylist.end();it++){ 24 if(it!=mylist.begin()) 25 cout<<" "; 26 cout<<*it; 27 } 28 cout<<endl; 29 } 30 return 0; 31 }
注:使用双向链表list
标签:begin ios span iostream i++ erase pre color 双向链表
原文地址:https://www.cnblogs.com/bxynlbyx/p/12828903.html