费了很大的力气在输出格式和读取输入数据上,输出和输入真得要按照题目描述非常严格的遵守:
#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;
}