【UVA】10935 Throwing cards away I(STL队列)

题目

题目
 


分析

练习STL
 


代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n) && n!=0)
	{
		queue<int> q;
		printf("Discarded cards:");
		for(int i=1;i<=n;i++) q.push(i);
		while(q.size()!=1)
		{
			if(q.front()!=1) printf(",");
			printf(" %d",q.front()); q.pop();
			int x=q.front(); q.pop();
			q.push(x);
		}
		printf("
Remaining card: %d
",q.front());
	}
	return 0;
}
原文地址:https://www.cnblogs.com/noblex/p/7897510.html