我爱水题,水题爱我!(毫无防备地留下了菜 的泪水)
这题仅仅考 queue 的简单运用
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) == 1 && n)
{
queue<int> q;
int f = 0;
for (int i = 1; i <= n; i++ )
{
q.push(i);
}
printf("Discarded cards:");
while(q.size() != 1)
{
if(!f) f = 1;
else printf(",");
printf(" %d",q.front());
q.pop();
int w = q.front();
q.pop(); q.push(w);
}
printf("\n");
printf("Remaining card: %d\n",q.front());
}
return 0;
}