#include #include #include #include using namespace std; struct Card { string s; }; bool comp(Card c1, Card c2){ if(c1.s[0] == c2.s[0]) { int n1, n2; if(c1.s[1] == 'A') n1 = 1; else if(c1.s[1] == 'T') n1 = 10; else if(c1.s[1] == 'J') n1 = 11; else if(c1.s[1] == 'Q') n1 = 12; else if(c1.s[1] == 'K') n1 = 13; else n1 = char(c1.s[1] - '0'); if(c2.s[1] == 'A') n2 = 1; else if(c2.s[1] == 'T') n2 = 10; else if(c2.s[1] == 'J') n2 = 11; else if(c2.s[1] == 'Q') n2 = 12; else if(c2.s[1] == 'K') n2 = 13; else n2 = char(c2.s[1] - '0'); return n1 < n2; } int s1, s2; if(c1.s[0] == 'D') s1 = 0; else if(c1.s[0] == 'C') s1 = 1; else if(c1.s[0] == 'H') s1 = 2; else s1 = 3; if(c2.s[0] == 'D') s2 = 0; else if(c2.s[0] == 'C') s2 = 1; else if(c2.s[0] == 'H') s2 = 2; else s2 = 3; return s1 < s2; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector cs; for(int i = 0; i < n; i++) { string s; cin >> s; cs.push_back(Card{s}); } sort(cs.begin(), cs.end(), comp); for(int i = 0; i < n; i++) { cout << cs[i].s << " "; } cout << endl; }