#include #include #include #include #include struct { int M_num(char x) const { if (isdigit(x)) return x-'0'; if (x == 'A') return 1; if (x == 'T') return 10; if (x == 'J') return 11; if (x == 'Q') return 12; if (x == 'K') return 13; return -1; } int M_suit(char x) const { if (x == 'D') return 0; if (x == 'C') return 1; if (x == 'H') return 2; if (x == 'S') return 3; return -1; } bool operator ()(const std::string& x, const std::string& y) const { if (x[0] != y[0]) return M_suit(x[0]) < M_suit(y[0]); return M_num(x[1]) < M_num(y[1]); } } cmp; int main() { size_t n; scanf("%zu", &n); std::vector a(n); for (auto& ai: a) { char buf[3]; scanf("%s", buf); ai = buf; } std::sort(a.begin(), a.end(), cmp); for (size_t i = 0; i < n; ++i) printf("%s%c", a[i].c_str(), i+1