UVa10935 - Throwing cards away I
来源:互联网 发布:网络与信息安全政府令 编辑:程序博客网 时间:2024/05/16 00:41
两个一个队列的,一个数组,我认为用队列比较简单
#include<iostream>#include<queue>using namespace std;queue<int> cards;int n;int main(){ while(cin>>n&&n){ for(int i=1;i<=n;i++) cards.push(i); cout<<"Discarded cards:"; int first=1; while(!cards.empty()){ if(cards.size()==1)break; if(first) { first=0;cout<<" "; } else cout<<", "; cout<<cards.front(); cards.pop(); cards.push(cards.front()); cards.pop(); } cout<<endl; cout<<"Remaining card: "<<cards.front()<<endl; while(!cards.empty()) cards.pop(); } return 0;}
#include<iostream>#include<vector>using namespace std;int n;vector<int> cards;int main(){ while(cin>>n&&n){ int first = 1; for(int i=1;i<=n;i++) cards.push_back(i); cout<<"Discarded cards:"; while(cards.size() != 1){ if(first) { first = 0; cout<<" "; } else cout<<", "; cout<<cards[0]; cards.erase(cards.begin()); cards.push_back(cards[0]); cards.erase(cards.begin()); } cout<<endl; cout<<"Remaining card: "<<cards[0]<<"\n"; cards.clear(); } return 0;}
0 0
- 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
- Uva10935 Throwing cards away I 【queue】【习题5-3】
- UVa10935-Throwing cards away I-卡片游戏-队列的运用
- Throwing cards away I
- Throwing cards away I
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
- 算法竞赛入门经典 第二版 习题5-3 卡片游戏 Throwing cards away I uva10935
- uva:Throwing cards away I
- 10935 - Throwing cards away I
- Throwing cards away I uva1594
- UVA_10935: Throwing cards away I
- Throwing cards away I--队列
- 如何获取搜狗输入法键盘的高度~搜狗输入法上边有个候选栏问题
- 深圳市全无卡停车场设备有限公司
- USACO section2.4 Bessie Come Home题解&代码
- 离散数学蕴含等值式前件为假命题为真的理解
- git基础操作和linux基础操作
- UVa10935 - Throwing cards away I
- POJ1011 Sticks DFS+剪枝
- Linux Platform Device and Driver : platform_add_devices()->platform_driver_register()
- 杭电第1008题-----Elevator
- 云计算的三种服务模式
- jquery实现点击劫持代码
- #294 (div.2) D.A and B and Interesting Substring
- 【日常学习】【非指针链表】Uva11988 - Broken Keyboard (a.k.a. Beiju Text)题解
- c++ – 标准容器可以继承吗