10935:Throwing cards away I

Throwing cards away I

 

queue

#include
#include
using namespace std;
int n;
int main(){
    while(scanf("%d",&n) && n){
        if(n == 1){ //注意n为1的情况
            puts("Discarded cards:\nRemaining card: 1");
            continue;
        }
        queueq;
        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;
}

你可能感兴趣的:(STL,UVa,水题)