美文网首页编程学习
UVA 10935 (Throwing cards away I

UVA 10935 (Throwing cards away I

作者: Gaolex | 来源:发表于2016-05-14 10:54 被阅读57次
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;
}

运行结果:

运行结果:

相关文章

网友评论

    本文标题:UVA 10935 (Throwing cards away I

    本文链接:https://www.haomeiwen.com/subject/xlbmrttx.html