#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef unsigned int nat; class Card; class Deck; ostream &operator <<(ostream &s, Card const &c); ostream &operator <<(ostream &s, Deck const &d); enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }; map suit_name = {{CLUBS, "Clubs"}, {DIAMONDS, "Diamonds"}, {HEARTS, "Hearts"}, {SPADES, "Spades"}}; map value_names = {{11, "Jack"}, {12, "Queen"}, {13, "King"}, {14, "Ace"}}; class Card { public: Card(nat value, Suit suit) : value{value}, suit{suit} {} private: nat value; Suit suit; friend ostream &operator <<(ostream &s, Card const &c); }; class Deck { public: Deck() { for(auto s : suit_name) { for(nat v = 2; v < 15; ++v) { cards.push_back( Card{v, s.first} ); } } } void add_shuffle_method(vector const &method) { shuffle_methods.push_back( vector(method)); } void shuffle(nat method) { vector new_order; for(nat i : shuffle_methods[method-1]) { new_order.push_back(cards[i-1]); } cards.swap(new_order); } private: vector cards; vector> shuffle_methods; friend ostream &operator <<(ostream &s, Deck const &d); }; ostream &operator <<(ostream &s, Card const &c) { if(c.value < 11) { cout << c.value; } else { cout << value_names.find(c.value)->second; } cout << " of " << suit_name.find(c.suit)->second; return s; } ostream &operator <<(ostream &s, Deck const &d) { for(auto c : d.cards) { cout << c << endl; } return s; } int main() { nat num_tests; cin >> num_tests; for(nat test = 0; test < num_tests; ++test) { nat num_shuffle_methods; cin >> num_shuffle_methods; Deck d; for(nat met = 0; met < num_shuffle_methods; ++met) { vector method(52); for(nat m = 0; m < 52; ++m) { cin >> method[m]; } d.add_shuffle_method(method); } string str; cin.ignore(1); getline(cin, str); while(!str.empty()) { d.shuffle(stoul(str)); getline(cin, str); } cout << d; if(test != (num_tests-1)) { cout << endl; } } return 0; }