#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n;
while(scanf("%d", &n) && n)
{
queue<int> q, ans;
for(int i = 1; i <= n; i++) q.push(i);
while(q.size() > 1)
{
ans.push(q.front());
q.pop();
q.push(q.front());
q.pop();
}
cout << "Discarded cards:";
for (int i = 0; i < n - 1;i++)
{
printf(" %d",ans.front());
if(i < n - 2) printf(",");
ans.pop();
}
cout << endl;
printf("Remaining card: %d\n",q.front()) ;
}
}
UVA-10935 Throwing cards away I 【队列+模拟】
最新推荐文章于 2021-08-23 23:19:17 发布