Uva10935
来源:互联网 发布:钢铁雄心2手机版数据 编辑:程序博客网 时间:2024/05/11 13:36
一.题目
题目链接:Uva10935
二.思路
典型的队列,对于每次的排,把第一个pop出来输出,第二个pop出来重新push进队尾,只剩1张牌的时候结束,注意只有一张牌时候的情况,详情看代码注释。
三.源代码
#include <iostream>#include <queue>using namespace std;int main() { queue<int> cards; //用队列做容器 int n, temp1, temp2; while ((cin >> n) && (n != 0)) { for (int i = 1; i <= n; i++) cards.push(i); if (n == 1) { //如果n=1直接输出 cout << "Discarded cards:" << endl << "Remaining card: 1" << endl; queue<int> empty; swap(cards, empty); continue; } cout << "Discarded cards: "; while (n >= 2) { temp1 = cards.front();//输出队头 cards.pop(); if (n == 2) //注意最后一个数据不需要逗号 cout <<temp1 << endl; else cout<<temp1 << ", "; temp2 = cards.front();//第二个元素添加至队尾 cards.pop(); cards.push(temp2); n--; } cout << "Remaining card: " << temp2 << endl; queue<int> empty; //清空容器 swap(cards, empty); } return 0;}
阅读全文
0 0
- uva10935
- UVA10935
- uva10935
- UVa10935
- Uva10935
- uva10935(栈)
- UVA10935-卡片游戏
- uva10935解题报告
- UVA10935纸牌问题
- UVa10935 - Throwing cards away I
- UVA10935 - Throwing cards away I
- uva10935 - Throwing cards away I
- UVa10935 - Throwing cards away I
- 5-3卡片游戏 uva10935
- 习题5-3 卡片游戏 UVa10935
- Uva10935——Throwing cards away I
- UVA10935 Throwing cards away I(队列)
- UVa10935(队列) Throwing cards away I
- 打印完数
- Android源代码 之 源代码分支、版本号、支持设备列表
- 上拉电阻与下拉电阻的区别
- (byte)0xaa
- Tomcat6.0+MyEclipse6.0+mysql5.0数据库连接池配置!
- Uva10935
- 我的SpringBoot心路历程(包括在Eclipse安装和配置Maven)
- 1. JNI Design
- 细说JAVA容器
- 笔记
- 某商场采用购物打折的优惠办法促销,每位顾客一次购物在100元以上,按九五折优惠; 在500元以上,按九折优惠;
- maven多profile 打包下 -P参和-D参数
- 【安全牛学习笔记】SQLMAP自动注入(二)
- Codeforces Round #447 (Div. 2) D 预处理+归并+ 二分