编程学习

UVA 10935 (Throwing cards away I

2016-05-14  本文已影响57人  Gaolex
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;
}

运行结果:

运行结果:
上一篇 下一篇

猜你喜欢

热点阅读