UVa 10935 Throwing cards away I【队列模拟】

原文网址:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1876


简单的队列模拟,结果pe了好久,无语,以后还是要耐心看题目要求啊...........


#include
#include
using namespace std;
int main()
{
	int n,tp;
	//freopen("shuju.txt","r",stdin);
	while(scanf("%d",&n),n)
	{
		queue q;int kase=0;
		for(int i=1;i<=n;++i)
		{
			q.push(i);
		}
		printf("Discarded cards:");
		while(q.size()>1)
		{
			if(kase)
			{
				printf(",");
			}
			printf(" %d",q.front());
			q.pop();
			tp=q.front();q.pop();
			q.push(tp);
			kase=1;
		}
		printf("\nRemaining card: %d\n",q.front());
	}
	return 0;
}


你可能感兴趣的:(队列)