#include
using namespace std;
#include
int main()
{
int t, n;
cin >> t;
while (t--)
{
cin >> n;
int k = 2;
list<int>mylist;
list<int>::iterator it;
for (int i = 1; i <= n; i++)
{
mylist.push_back(i);
}
while (mylist.size() > 3)
{
int num = 1;
for (it = mylist.begin(); it != mylist.end(); it++)
{
if (num++ % k == 0)
{
it = mylist.erase(it);//erase()返回值是指向被删元素的下一元素的指针
}
else
{
it++;
}
}
k == 2 ? k = 3 : k = 2;
}
for (it = mylist.begin(); it != mylist.end(); it++)
{
if (it != mylist.begin())
{
cout << " ";
}
cout << *it;
}
cout << endl;
}
return 0;
}
具体什么错误(⊙o⊙)哇 看看
报的啥错误
对list遍历时不要修改list