#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) string card[60]; int n; map change; void srot_mark(){ for(int i = 0;i < n-1;i++){ for(int j = 0;j < n-1;j++){ if(card[j+1][0] == 'D' && card[j][0] != 'D') swap(card[j],card[j+1]); else if(card[j][0] == 'S' && card[j+1][0] != 'S') swap(card[j],card[j+1]); else if(card[j][0] == 'H' && card[j+1][0] == 'C') swap(card[j],card[j+1]); } } } void srot_num(){ for(int i = 0;i < n-1;i++){ for(int j = 0;j < n-1;j++){ int numa,numb; numa = change[card[j][1]]; numb = change[card[j+1][1]]; if(numa > numb && card[j][0] == card[j+1][0]){ swap(card[j],card[j+1]); } } } } int main() { change['A'] = 1; change['T'] = 10; change['J'] = 11; change['Q'] = 12; change['K'] = 13; char num = '2'; for(int i = 2;i <= 9;i++){ change[num] = i; num++; } cin >> n; for(int i = 0;i < n;i++){ cin >> card[i]; } srot_mark(); srot_num(); for(int i = 0;i < n;i++) { cout << card[i] << " "; } cout << endl; return 0; }