Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:

  Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck.

  Your task is to find the sequence of discarded cards and the last, remaining card.

Input

  Each line of input (except the last) contains a number n≤ 50. The last line contains ‘0’ and this line should not be processed.

Output

  For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format.

Sample Input

7
19
10
6
1
0

Sample Output

Discarded cards: 1, 3, 5, 7, 4, 2
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14
Remaining card: 6
Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8
Remaining card: 4
Discarded cards: 1, 3, 5, 2, 6
Remaining card: 4
Discarded cards:
Remaining card: 1

HINT

  简单的队列操作,需要注意的是当n=1时应该如何输出,第一行后面无空格,具体键上面样例输入。

Accepted

#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n,t;
while (cin>>n&&n)
{
queue<int>game;
for (int i = 1;i <= n;i++)game.push(i);
cout << "Discarded cards:";
for (int i = 1;game.size() > 1;i++)
{
cout << " " << game.front();
game.pop();
game.push(game.front());
game.pop();
if (game.size() > 1)cout << ",";
}
cout << endl << "Remaining card: " << game.front() << endl;
}
}

Throwing cards away I UVA - 10935的更多相关文章

  1. UVa 10935 - Throwing cards away I (队列问题)

    原题 Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the to ...

  2. Throwing cards away I

    Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the top a ...

  3. UVa---------10935(Throwing cards away I)

    题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 ...

  4. [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...

  5. Throwing cards away I uva1594

     Throwing cards away I Given is an ordered deck of  n  cards numbered 1 to n  with card 1 at the t ...

  6. 紫书第五章训练3 D - Throwing cards away I

    D - Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top ...

  7. UVA10940 - Throwing cards away II(找到规律)

    UVA10940 - Throwing cards away II(找规律) 题目链接 题目大意:桌上有n张牌,依照1-n的顺序从上到下,每次进行将第一张牌丢掉,然后把第二张放到这叠牌的最后.重复进行 ...

  8. Uva 10935 Throwing cards away I

    题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最 ...

  9. UVa 10935 (水题) Throwing cards away I

    直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...

随机推荐

  1. 微信小程序:条件渲染wx:if和hidden

    一.条件渲染:wx:if,wx:elif,wx:else 花括号中的true或false可以改成变量从而来动态显示. 二.hidden 只显示hidden2 当标签不是频繁切换显示(控制是否渲染到页面 ...

  2. Markdown的基本用法与下载

    Markdown的基本用法与下载typora 下载typora 1.在浏览器搜索typora 2.然后点进去 3.往下翻点击Download 4.看自己是什么系统然后在选择 5.选好系统以后再去去选择 ...

  3. Markdown基础使用方法

    Markdown基础使用方法 标题的几种用法 * 选中标题(Ctrl+1~Crtl+6),分别为标题1-6.* #+空格+内容 为一级标题##+空格+内容为二级标题:以此类推. 字体快捷键及使用方法 ...

  4. JWT原理及常见攻击方式

    JWT的全称是Json Web Token.它遵循JSON格式,将用户信息加密到token里,服务器不保存任何用户信息,只保存密钥信息,通过使用特定加密算法验证token,通过token验证用户身份. ...

  5. iPhone去除input默认样式

    /*<!---->去掉苹果短的样式*/ input[type="button"], input[type="submit"], input[type ...

  6. 剑指 Offer 66. 构建乘积数组 + 思维

    剑指 Offer 66. 构建乘积数组 Offer_66 题目描述 题解分析 java代码 package com.walegarrett.offer; /** * @Author WaleGarre ...

  7. POJ-2236(并查集)

    Wireless NetWork POJ-2236 需要注意这里的树的深度需要初始化为0. 而且,find函数需要使用路径压缩,这里的unint合并函数也使用了优化(用一开始简单的合并过不了). #i ...

  8. 日志文件迁移至OSS

    一台服务器在用阿里云ECS,因为穷,磁盘空间有限,服务器日志文件每天都在增长,需要定期清理释放磁盘空间,想到几种解决方案: 写任务定时备份到本地服务器 直接下载到本地用移动硬盘备份 备份到阿里云OSS ...

  9. 基于 vagrant搭建移动端的开发环境

    # 后端开发环境Homestead启动 Homestead 之前,确保 VirtualBox .Vagrant.Git 软件己安装. ## 安装 laravel/homesteadvagrant bo ...

  10. Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置

    之后随笔将更多笔墨着重于NNIE开发系列,下文是关于Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置,目前项目需要对 ...