Uva10935 Throwing cards away I 【queue】【习题5-3】
来源:互联网 发布:移动数据俱乐部 编辑:程序博客网 时间:2024/05/15 01:51
题目:Throwing cards away I
题意:1~n张牌,把第一张扔掉,然后把新的第一张牌放到最后,输出扔的牌和最后一张牌
思路:就是一个最基本的队列操作,特殊数据:n = 1:cout << "Discarded cards:\nRemaining card: 1\n";
代码:
#include <iostream>#include <queue>using namespace std;queue<int>Q;int main(){ int n,a[55]; while(cin >> n && n) { if(n == 1) { cout << "Discarded cards:\nRemaining card: 1\n"; continue; } while(!Q.empty()) Q.pop(); for(int i=1;i<=n;i++) Q.push(i); int cot = 0; while(!Q.empty()) { a[cot++] = Q.front(); Q.pop(); if(!Q.empty()){ Q.push(Q.front()); Q.pop();} } int i; cout << "Discarded cards: "; for(i=0;i<cot-2;i++) cout << a[i] << ", "; cout << a[i++] << endl; cout << "Remaining card: " << a[i] << endl; } return 0;}
0 0
- Uva10935 Throwing cards away I 【queue】【习题5-3】
- 算法竞赛入门经典 第二版 习题5-3 卡片游戏 Throwing cards away I uva10935
- UVa10935 - Throwing cards away I
- UVA10935 - Throwing cards away I
- uva10935 - Throwing cards away I
- UVa10935 - Throwing cards away I
- Uva10935——Throwing cards away I
- UVA10935 Throwing cards away I(队列)
- UVa10935(队列) Throwing cards away I
- uva 10935 Throwing cards away I 习题5-3 (STL queue练习)
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
- UVa 10935 Throwing cards away I(习题5-3)
- UVa10935-Throwing cards away I-卡片游戏-队列的运用
- UVA 10935 Throwing cards away I (queue)
- 习题5-3 UVA 10935 Throwing cards away I 卡片游戏
- 习题5-3 卡片游戏(Throwing cards away I, UVa 10935)
- Throwing cards away I
- Throwing cards away I
- 新闻demo
- android - Volley框架请求获取Cookie和带Cookie请求链接和带参数Params
- android View 绘制解析
- 立个flag
- cocos关于pageview嵌套listview,事件响应问题
- Uva10935 Throwing cards away I 【queue】【习题5-3】
- HDU 1964 Pipes
- 零食店
- ssm框架整合开发
- 贪吃蛇
- MCS-51单片机 特殊功能寄存器(SFR)
- Android7.0 快速开启分屏功能
- 算法学习系列之找出斐波那契数
- android graphic(9)—开发者选项关闭HW overlays