UVa 10935 - Throwing cards away I
2018-01-28 11:51
357 查看
题意
(摘自紫书)桌上有n(n≤50)张牌,从第一张牌(即位于顶面的牌)开始,从上往下依次编号为1~n。当至少还剩下两张牌时进行以下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后。输入每行包含一个n,输出每次扔掉的牌以及最后剩下的牌。
思路
水题STL队列
记录
之前没考虑到的PE情况:Input
1
Output
Discarded cards:
Remaining card: 1
*(第一行行末不应该有空格)
AC代码
#include <iostream> #include <cstdio> #include <queue> using namespace std; queue<int> s; int main() { int n, i; while( cin >> n && n ){ const int n_bg = n; for( i = 1; i <=n; i++ ) s.push(i); printf("Discarded cards:"); while( n >= 2 ) { if( n != n_bg ) printf(",") ; printf(" %d",s.front()); s.pop(); n--; s.push(s.front()); s.pop(); } puts(""); printf("Remaining card: %d\n",s.front()); s.pop(); } return 0; }
相关文章推荐
- UVa 10935 Throwing cards away I【队列】
- UVA 10935 - Throwing cards away I
- UVA 10935 - Throwing cards away I
- Throwing cards away I UVA - 10935
- UVa 10935 - Throwing cards away I
- Throwing cards away I 卡牌游戏 UVA 10935
- UVa 10935 - Throwing cards away I
- UVa 10935 - Throwing cards away I
- UVA - 10935 Throwing cards away I
- 卡片游戏(Throwing cards away I,UVa 10935)
- UVA10935 Throwing cards away I【模拟+queue+循环队列】
- UVa10935-Throwing cards away I-卡片游戏-队列的运用
- UVA 10935 Throwing Cards Away I 卡片游戏
- Throwing cards away I UVA - 10935
- UVa 10935 - Throwing cards away I
- UVA -10935-卡片游戏-Throwing cards away
- UVa 10935 Throwing cards away I
- Uva 10935 Throwing cards away I
- UVa 10935 - Throwing cards away I
- UVa 10935 - Throwing cards away I STL