2018学校暑期集训第一天——C++与STL

例二  ——  UVA - 10935

Throwing cards away I

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.

Each line of input (except the last) contains a number n ≤ 50. The last line contains 0 and this line should not be processed. 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
0

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

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 1010
#define MAXSIZE 200
using namespace std;int main(void)
{int n;queue<int> q;while (scanf("%d", &n) && n != 0) {for (int i = 1; i <= n; i++) q.push(i);printf("Discarded cards:");while (q.size() > 1) {printf(" %d", q.front());q.pop();int front = q.front();q.pop();if (!q.empty())printf(",");q.push(front);}printf("\nRemaining card: %d\n", q.front());q.pop();}return 0;
}

注:此题主要练习STL的queue

暑期集训1:C++STL 例2:UVA-10935相关推荐

  1. 暑期集训1:C++STL 例1:UVA-10815

    2018学校暑期集训第一天--C++与STL 例一  --  UVA - 10815 Andy's First Dictionary Description XY学长刚刚立下了再不过CET就直播xx的 ...

  2. 暑期集训1:C++STL 例3:UVA-12100

    2018学校暑期集训第一天--C++与STL 例三  --  UVA - 12100 Printer Queue The only printer in the computer science st ...

  3. 暑期集训1:C++STL 练习题E:POJ-2431

    2018学校暑期集训第一天--C++与STL 练习题E --  POJ - 2431 E - 二律背反的对偶 A group of cows grabbed a truck and ventured ...

  4. 暑期集训1:C++STL 练习题D:HDU-1509

    2018学校暑期集训第一天--C++与STL 练习题D --  HDU - 1509 D - 振电迁移的日蚀 Message queue is the basic fundamental of win ...

  5. 暑期集训1:C++STL 练习题C:HDU-1263

    2018学校暑期集训第一天--C++与STL 练习题C --   HDU - 1263 C - 亡失流转的孤独 夏天来了~~好开心啊,呵呵,好多好多水果~~  Joe经营着一个不大的水果店.他认为生存 ...

  6. 暑期集训1:C++STL 练习题B:HDU-1004

    2018学校暑期集训第一天--C++与STL 练习题B --  HDU - 1004 B - 双对福音的协议 Contest time again! How excited it is to see ...

  7. 暑期集训1:C++STL 练习题A:POJ-1833

    2018学校暑期集训第一天--C++与STL 练习题A -- POJ-1833 A - 闭时曲线的引言 Time Limit: 1000MS   Memory Limit: 30000K Total ...

  8. 暑期集训4:栈,树,优先队列 例 :  UVA - 514 ​​​​​​​​​​​​​​

    2018学校暑期集训第四天--栈,树,优先队列 例题  --   UVA - 514 Rails There is a famous railway station in PopPush City. ...

  9. 暑期集训2:ACM基础算法 例2:POJ-2456

    2018学校暑期集训第二天--ACM基础算法 例二  --   POJ - 2456 Aggressive cows Farmer John has built a new long barn, wi ...

最新文章

  1. 根据PromiseA+规范实现Promise
  2. 利用Jenkins的Pipeline实现集群自动化部署SpringBoot项目
  3. 可配置循环左右滚动例子
  4. VB讲课笔记07:控制结构
  5. 解析Linux内核的基本的模块管理与时间管理操作---超时处理【转】
  6. hibernate mysql longblob_为什么不能将JPA / hibernate映射到MySQL blob类型?
  7. 大数据开发之Hadoop---初始Hadoop
  8. sql函数 StringSplit(SELECT * from Split('黄色,蓝色,黑色',','))
  9. 一个正经的前端学习 开源 仓库(阶段二十六)
  10. 拍照识别植物app哪个好?来看看这几个工具
  11. 工业互联网的数据集成
  12. 系统服务器与手机关系,手机与云服务器交互
  13. centos7 如何编译ffmpeg 带x265和nvenc
  14. linux - 异常:安装包冲突 conflicts with
  15. win10显卡驱动报错怎么办【系统天地】
  16. 线程的 run() 和 start() 有什么区别?
  17. 拿下18Koffer,黑马老学长分享了4点学习建议!
  18. Lucas定理扩展Lucas
  19. 【渗透测试】ew代理三层靶机穿透+proxifier配置规则
  20. IOS版伪春菜开发笔记1.2之图层的遮罩及黑色透明处理

热门文章

  1. Linux--文件管理以及权限的修改
  2. 【JAVA零基础入门系列】Day2 Java集成开发环境IDEA
  3. iOS富文本字符串AttributedString详解
  4. 最锋利的Visual Studio Web开发工具扩展:Web Essentials详解(转)
  5. 提高网站页面收录的几个方法 返回列表 发新帖回复
  6. Facebook的加密货币即将到来会对整个加密货币领域意味着什么
  7. 区块链从一夜暴富到一夜暴“负”的辛酸史
  8. gitter 卸载_最佳Gitter频道:VR和AR
  9. 搭建Zabbix分布式监控
  10. 二叉树:root==NULL和*root==NULL的区别