UVa 10935 (水题) Throwing cards away I

直接用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 }
代码君

 

posted @ 2015-04-24 13:45  AOQNRMGYXLMV  阅读(176)  评论(0编辑  收藏  举报