#include #include #include #include enum Sute { D, C, H, S }; class Card { public: Card(const std::string &arg = "D1") { switch (arg.front()) { case('D') : sute = D; break; case('C') : sute = C; break; case('H') : sute = H; break; case('S') : sute = S; break; } num = map.at(arg.back()); expression = arg; } bool operator<(const Card &other) { return (sute < other.sute) || ((sute == other.sute) && (num < other.num)); } Sute sute; int num; std::string expression; static std::map map; }; std::map Card::map = { {'A', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'T', 10}, {'J', 11}, {'Q', 12}, {'K', 13} }; void sort(std::vector &vector, const int &left, const int &right) { if (left < right) { auto l = left, r = right, pivot = (left + right) / 2; while (l < r) { while (vector.at(l) < vector.at(pivot))++l; while (vector.at(pivot) < vector.at(r))--r; if (l < r) { auto temp = vector.at(l); vector.at(l) = vector.at(r); vector.at(r) = temp; ++l; --r; } } sort(vector, left, l - 1); sort(vector, l, right); } } int main() { int n; std::cin >> n; std::vector vector(n); for (auto &i : vector) { std::string s; std::cin >> s; i = Card(s); } sort(vector, 0, n - 1); std::cout << vector.front().expression; for (auto i = 1; i < n; ++i) { std::cout << " " << vector.at(i).expression; } return 0; }