#include
using namespace std;
#include
int main(void)
{
list Boy;
for(int i = 1; i <= 100; ++i)
{
Boy.push_back(i);
}
list::iterator it = Boy.begin();
int num = 1;
while(Boy.size() > 1)
{
if(num%3 == 0)
{
Boy.remove(*it);
}
else
{
++it;
}
if(it == Boy.end())
{
it = Boy.begin();
}
++num;
}
cout << *it << endl;
return 0;
}
你應該yerase刪除,同時刪除後要調整迭代器,不然會失效。