10935:Throwing cards away I

Throwing cards away I

 

queue

#include<cstdio>
#include<queue>
using namespace std;
int n;
int main(){
    while(scanf("%d",&n) && n){
        if(n == 1){ //注意n为1的情况
            puts("Discarded cards:\nRemaining card: 1");
            continue;
        }
        queue<int>q;
        for(int i = 3;i <= n;i++) q.push(i);
        q.push(2);
        printf("Discarded cards: 1");
        while(q.size() >= 2){
            int t = q.front();q.pop();
            printf(", %d",t);
            q.push(q.front());q.pop();
        }
        printf("\nRemaining card: %d\n",q.front());
    }
    return 0;
}

posted @ 2018-04-21 22:45  ACLJW  阅读(139)  评论(0编辑  收藏  举报