简单队列模拟
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
int N;
while (cin >> N&&N)
{
cout << "Discarded cards:";
queue<int> q;
for (int i = 1;i <= N;i++)q.push(i);
bool first = true;
while (q.size() >= 2)
{
if (first) { cout << " " << q.front();first = false;q.pop();q.push(q.front());q.pop();continue; }
cout << ", " << q.front();q.pop();
q.push(q.front());q.pop();
}
cout << endl;
cout << "Remaining card: " << q.front() << endl;
}
return 0;
}