programming-challenges Stack 'em Up (110205) 题解

费了很大的力气在输出格式和读取输入数据上,输出和输入真得要按照题目描述非常严格的遵守:

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>

using namespace std;

struct Poker {
	string suit; 
	int value; 

	Poker(string s, int v) : suit(s), value(v) {}
};
bool operator<(Poker& p1, Poker& p2) {
	return (p1.suit < p2.suit) || (p1.suit == p2.suit && p1.value < p2.value); 
}
ostream& operator<<(ostream& os, Poker p) {
	if (p.value < 11) return os << p.value << " of " << p.suit << endl;
	else if (p.value == 11) return os << "Jack of " << p.suit << endl; 
	else if (p.value == 12) return os << "Queen of " << p.suit << endl;
	else if (p.value == 13) return os << "King of " << p.suit << endl;
	else if (p.value == 14) return os << "Ace of " << p.suit << endl;

	return os; 
}

int main() {
	vector<Poker> pokers; 
	
	for (int i = 2; i <= 14; i++) {
		pokers.push_back(Poker("Clubs", i)); 
		pokers.push_back(Poker("Diamonds", i));
		pokers.push_back(Poker("Hearts", i));
		pokers.push_back(Poker("Spades", i));
	}

	sort(pokers.begin(), pokers.end());

	int TC = 0; cin >> TC; 
	string ts; 
	getline(cin, ts); 
	bool blank = false;
	for (int i = 0; i < TC; i++) {
		int shuffleNum = 0; cin >> shuffleNum; 
		vector<int> shuffles[110]; 
		for (int j = 1; j <= shuffleNum; j++) {
			shuffles[j].push_back(0);
			for (int k = 1; k <= 52; k++) {
				int po = 0; 
				cin >> po; 
				shuffles[j].push_back(po); 
			}
		}
		getchar(); 

		vector<int> position; 
		for (int j = 0; j <= 52; j++) position.push_back(j);

		char input[50];
		while (gets(input) && strlen(input)) {
			int num = atoi(input); 
			vector<int> positionBack = position; 
			for (int j = 0; j < shuffles[num].size(); j++) {
				positionBack[j] = position[shuffles[num][j]]; 
			}
			position = positionBack; 
		}

		if (blank)
			cout << endl;
		blank = true;
		for (int j = 1; j <= 52; j++) {
			cout << pokers[position[j] - 1]; 
		}
	}

	return 0; 
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值