您的位置:首页 > 其它

Throwing cards away I 卡牌游戏 UVA 10935

2017-01-04 22:48 337 查看
解题思路:本题通过STL中的队列queue很容易就写出代码,唯一值得注意的是当输入为1时;

#include<cstdio>
#include<queue>
using namespace std;
queue<int>q;
int main(){
    int n;
    while(scanf("%d",&n)==1 && n){
        for(int i=1;i<=n;i++)
            q.push(i);
            int len=q.size();
            if(len==1)printf("Discarded cards:\n");
            else printf("Discarded cards: ");
        while(len>=3){
            printf("%d, ",q.front());
            q.pop();
            int temp=q.front();
            q.pop();
            q.push(temp);
            len=q.size();
        }
        if(len!=1)
        {
        printf("%d\n",q.front());
        q.pop();
        }
        printf("Remaining card: %d\n",q.front());
        q.pop();
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: