//@author:yzj Date:2015/07/25
//sourse:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82493#problem/E
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int n;
int main()
{
//freopen("F:/yzj/cppCode/input.txt", "r", stdin);
while(scanf("%d", &n) && n)
{
queue<int> que;
for(int i = 1; i <= n; i++)
{
que.push(i);
}
printf("Discarded cards:");
while(que.size()>2)
{
int dis = que.front();
printf(" %d,", dis);
que.pop();
int sec = que.front();
que.pop();
que.push(sec);
}
//n==1的时候需要特殊处理,刚开始时认为Discarded cards:为1
//然后出错了
if(n==1)
{
printf("\n");
printf("Remaining card: 1\n");
}
else
{
int dis = que.front();
printf(" %d\n", dis);
que.pop();
int sec = que.front();
que.pop();
printf("Remaining card: %d\n", sec);
}
}
/*
printf("Discarded cards:");
while(que.size())
{
if(que.size()==1)break;
if(que.size()==2)
{
printf(" %d", que.front());que.pop();break;
}
else
{
printf(" %d,", que.front());que.pop();
}
que.push(que.front());que.pop();
}
printf("\n");
printf("Remaining card: %d\n", que.front());que.pop();
}
*/
return 0;
}
队列
最新推荐文章于 2024-03-09 10:00:00 发布