UVA-10935 Throwing cards away I

Vjudge题目链接,STL的队列,模拟队列即可,注意输入n=1的情况(坑点,每行首尾没空格)。

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

    return 0;
}

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