UVA 10935

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<queue>
using namespace std;
int main(){
    int n,x,m;
    queue<int> q;
    while(scanf("%d",&n)==1&&n){
        for(int i=1;i<=n;i++)
            q.push(i);
        printf("Discarded cards:");
    while(!q.empty()){
        if(q.size()==1) break;
        if(q.size()==2)
            printf(" %d",q.front());
        else
             printf(" %d,",q.front());
        q.pop();
        q.push(q.front());
        q.pop();

    }
    printf("\n");
    printf("Remaining card: %d\n",q.front());
    q.pop();
}
  return 0;
}

 

posted @ 2015-12-21 14:09  咸咸的告别  阅读(103)  评论(0编辑  收藏  举报