习题5-3 卡片游戏 UVa10935

1.题目描述:点击打开链接

2.解题思路:模拟题目过程即可

3.代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<cassert>
#include<cstdlib>
#include<ctime>
#include<functional>
using namespace std;
queue<int>card;
int n;

int main()
{
	while (cin >> n&&n)
	{
		for (int i = 1; i <= n; i++)
			card.push(i);
		cout << "Discarded cards:";
		while (card.size() >= 2)
		{
			cout << ' '<<card.front();
			if (card.size() != 2)
				cout << ',';
			card.pop();
			card.push(card.front());
			card.pop();
		}
		cout << endl;
		cout << "Remaining card: "<<card.front()<<endl;
		card.pop();
	}
	return 0;
}



你可能感兴趣的:(uva)