码迷,mamicode.com
首页 > Windows程序 > 详细

UVa 10935 (水题) Throwing cards away I

时间:2015-04-24 15:49:17      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

直接用STL里的queue模拟即可。

技术分享
 1 #include <cstdio>
 2 #include <queue>
 3 using namespace std;
 4 
 5 const int maxn = 60;
 6 int discarded[maxn], cnt;
 7 
 8 int main()
 9 {
10     int n;
11     while(scanf("%d", &n) == 1 && n)
12     {
13         cnt = 0;
14         queue<int> Q;
15         for(int i = 1; i <= n; i++) Q.push(i);
16         while(Q.size() >= 2)
17         {
18             discarded[cnt++] = Q.front(); Q.pop();
19             int t = Q.front(); Q.pop(); Q.push(t);
20         }
21         printf("Discarded cards:");
22         for(int i = 0; i < cnt; i++)
23         {
24             if(i) printf(",");
25             printf(" %d", discarded[i]);
26         }
27         printf("\n");
28         printf("Remaining card: %d\n", Q.front());
29     }
30 
31     return 0;
32 }
代码君

 

UVa 10935 (水题) Throwing cards away I

标签:

原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/4453256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!