UVa-10935 - Throwing cards away I

简单的队列。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<queue>
 5 using namespace std;
 6 int main()
 7 {
 8     //freopen("in.in","r",stdin);
 9     //freopen("out.in","w",stdout);
10     int n;
11     while(~scanf("%d",&n)&&n)
12     {
13         queue<int> q;
14         for(int i=1;i<=n;i++) q.push(i);
15         printf("Discarded cards:");
16         if(n>1)
17         {
18             for(int i=1;i<=n-2;i++)
19             {
20                 printf(" %d,",q.front());
21                 q.pop();
22                 q.push(q.front());
23                 q.pop();
24             }
25             printf(" %d\n",q.front());
26             q.pop();
27         }
28         else printf("\n");
29         printf("Remaining card: %d\n",q.front());
30     }
31 }

 

posted on 2015-07-17 01:41  windrises  阅读(144)  评论(0编辑  收藏  举报

导航