Throwing cards away I 卡牌游戏 UVA 10935
2017-01-04 22:48
337 查看
解题思路:本题通过STL中的队列queue很容易就写出代码,唯一值得注意的是当输入为1时;
#include<cstdio>
#include<queue>
using namespace std;
queue<int>q;
int main(){
int n;
while(scanf("%d",&n)==1 && n){
for(int i=1;i<=n;i++)
q.push(i);
int len=q.size();
if(len==1)printf("Discarded cards:\n");
else printf("Discarded cards: ");
while(len>=3){
printf("%d, ",q.front());
q.pop();
int temp=q.front();
q.pop();
q.push(temp);
len=q.size();
}
if(len!=1)
{
printf("%d\n",q.front());
q.pop();
}
printf("Remaining card: %d\n",q.front());
q.pop();
}
return 0;
}
#include<cstdio>
#include<queue>
using namespace std;
queue<int>q;
int main(){
int n;
while(scanf("%d",&n)==1 && n){
for(int i=1;i<=n;i++)
q.push(i);
int len=q.size();
if(len==1)printf("Discarded cards:\n");
else printf("Discarded cards: ");
while(len>=3){
printf("%d, ",q.front());
q.pop();
int temp=q.front();
q.pop();
q.push(temp);
len=q.size();
}
if(len!=1)
{
printf("%d\n",q.front());
q.pop();
}
printf("Remaining card: %d\n",q.front());
q.pop();
}
return 0;
}
相关文章推荐
- UVA 10935 - Throwing cards away I
- Uva10935——Throwing cards away I
- UVa 10935 - Throwing cards away I
- UVa 10935 Throwing cards away I(习题5-3)
- UVA 10935 - Throwing cards away I
- uva 10935 Throwing cards away I
- Uva 10935 Throwing cards away I
- UVa 10935 (水题) Throwing cards away I
- UVa-10935 - Throwing cards away I
- Uva 10935 Throwing cards away I
- 【习题5-3 UVA-10935】Throwing cards away I
- 习题5-3 卡片游戏(Throwing cards away I, UVa 10935)
- UVA - 10935 Throwing cards away I
- UVa 10935 - Throwing cards away I
- Throwing cards away I UVA - 10935
- UVa 10935 Throwing cards away I【队列模拟】
- 经典第五章 习题 5-3 UVA 10935 Throwing cards away I(队列的简单应用)
- Uva 10935 Throwing cards away I
- 习题5-3 UVA 10935 Throwing cards away I 卡片游戏
- UVA10935 - Throwing cards away I