UVA 10935 (Throwing cards away I)

UVA 10935 (Throwing cards away I)_第1张图片
Throwing cards away I
#include 
#include 
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        list 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;
}

运行结果:

UVA 10935 (Throwing cards away I)_第2张图片
运行结果:

你可能感兴趣的:(UVA 10935 (Throwing cards away I))