原题链接:https://vjudge.net/problem/UVA-10935
分类:<vector>
备注:水题
前言:看了一眼我以前的代码,怎么感觉queue才是正常做法呢…
代码如下:
#include<cstdio>
#include<vector>
using namespace std;
int main(void)
{
int n;
while (~scanf("%d", &n) && n)
{
vector<int>card;
for (int i = 0; i < n; i++)card.push_back(i);
printf("Discarded cards:");
for (int i = 0; i < n - 1; i++)
{
printf(" %d", *card.begin() + 1);
if (i != n - 2)printf(",");
card.erase(card.begin());
card.push_back(*card.begin());
card.erase(card.begin());
}
printf("\nRemaining card: %d\n", *card.begin() + 1);
}
return 0;
}