UVA 10935 - Throwing cards away I

UVA 能上去啦,哈哈。

WA了一次。。。这个坑爹的输入1的时候应该输出

Discarded cards:
Remaining card: 1

 

用C++自带的模版类方便多了。。。。

#include<iostream>
#include<queue>
using namespace std;
queue<int> q;
int main() 
{
	int n,i;
	while( cin>>n,n)
	{
		if(n==1)
		{
			cout<<"Discarded cards:\nRemaining card: 1\n";
			continue;
		}
		for(i=0;i<n;i++)
			q.push(i+1);
		int ans[51],count=0;
		while(!q.empty())
		{
			ans[count++]=q.front();
			q.pop();
			if(q.empty()) break;
			q.push(q.front());
			q.pop();
		}
		cout<<"Discarded cards: ";
		for(i=0;i<count-2;i++)		
			cout<<ans[i]<<", ";
		cout<<ans[i++]<<endl;
		cout<<"Remaining card: "<<ans[i]<<endl;
	}
	return 0;
}



posted @ 2013-07-15 21:43  hr_whisper  阅读(157)  评论(0编辑  收藏  举报