UVa 10935卡片游戏

很简单的一个题目,就是队列的运用就可以了,就是注意一下1的时候的情况就可以了。

 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     queue<int> s;
 8     int n,t;
 9     while (cin >> n && n)
10     {
11         for (int i = 1; i <= n; i++)
12         {
13             s.push(i);
14         }
15         int flag = 1;
16         if(n>1) cout << "Discarded cards: ";
17         else    cout << "Discarded cards:" << endl;
18         while (n > 1)
19         {
20             if (flag == 1)
21             {
22                 t = s.front();
23                 s.pop();
24                 cout << t;
25                 if (n > 2) cout << ", ";
26                 else cout << endl;
27                 flag = 0;
28                 n--;
29             }
30             else
31             {
32                 t = s.front();
33                 s.pop();
34                 s.push(t);
35                 flag = 1;
36             }
37         }
38         cout << "Remaining card: " << s.front() << endl;
39         s.pop();
40     }
41     return 0;
42 }

2016-11-23 22:55:23

转载于:https://www.cnblogs.com/zyb993963526/p/6095919.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值