Throwing cards away I
#include <iostream>
#include <list>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
list<int> cards;
for (int i = 1; i <= n; i++)
cards.push_back(i);
cout << "Discarded cards:";
while (n >= 2)
{
cout << cards.front() << ' ';
cards.pop_front();
cards.push_back( cards.front() );
cards.pop_front();
n -= 1;
}
cout << "\nRemaining card:" << cards.front() << '\n';
}
system("pause");
return 0;
}
运行结果:
运行结果: