#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { int n; scanf("%d", &n); pair vpi[n]; for (int i = 0; i < n; i++) { char cc[3]; scanf("%s", cc); int a, b; switch(cc[0]) { case 'D': b = 0; break; case 'C': b = 1; break; case 'H': b = 2; break; case 'S': b = 3; break; default: break; } switch(cc[1]) { case 'A': a = 1; break; case 'T': a = 10; break; case 'J': a = 11; break; case 'Q': a = 12; break; case 'K': a = 13; break; default: a = cc[1]-'0'; break; } vpi[i] = make_pair(b, a); } sort(vpi, vpi+n); for (int i = 0; i < n; i++) { char ans[3]; switch(vpi[i].first) { case 0: ans[0] = 'D'; break; case 1: ans[0] = 'C'; break; case 2: ans[0] = 'H'; break; case 3: ans[0] = 'S'; break; default: break; } switch(vpi[i].second) { case 1: ans[1] = 'A'; break; case 10: ans[1] = 'T'; break; case 11: ans[1] = 'J'; break; case 12: ans[1] = 'Q'; break; case 13: ans[1] = 'K'; break; default: ans[1] = '0'+vpi[i].second; break; } printf("%s ", ans); } puts(""); }