UVA-10935 Throwing cards away I 【队列+模拟】

#include
#include
using namespace std;
int main()
{
    int n;
    while(scanf("%d", &n) && n)
    {
        queue q, ans;
        for(int i = 1; i <= n; i++) q.push(i);
        while(q.size() > 1)
        {
            ans.push(q.front());
            q.pop();
            q.push(q.front());
            q.pop();
        }
        cout << "Discarded cards:";
        for (int i = 0; i < n - 1;i++)
        {
            printf(" %d",ans.front());
            if(i < n - 2) printf(",");
            ans.pop();
        }
        cout << endl;
          printf("Remaining card: %d\n",q.front()) ;

    }
}

你可能感兴趣的:(刷题)