您的位置:首页 > 其它

【习题5-3 UVA-10935】Throwing cards away I

2017-10-14 17:03 489 查看

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


用STL的queue写

【代码】

#include <bits/stdc++.h>
using namespace std;

queue <int> dl;
vector <int> v;
int n;

int main()
{
//freopen("F:\\rush.txt", "r", stdin);
while (~scanf("%d", &n) && n)
{
v.clear();
while (!dl.empty()) dl.pop();

for (int i = 1; i <= n; i++) dl.push(i);
for (int i = 1; i <= n - 1; i++)
{
v.push_back(dl.front());
dl.pop();
dl.push(dl.front());
dl.pop();
}
printf("Discarded cards:");
for (int i = 0; i < n - 1; i++)
{
printf(" %d%c", v[i], i == n - 2 ? '\n' : ',');
}
if (n == 1) puts("");
printf("Remaining card: %d\n", dl.front());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: