using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace No267 { class MainClass { private class CustomComparer : IComparer { private readonly IDictionary orders = new Dictionary(); private readonly IDictionary numbers = new Dictionary(); public CustomComparer() { orders.Add('D', 1); orders.Add('C', 2); orders.Add('H', 3); orders.Add('S', 4); for(char c = '2';c <= '9';c++) { numbers.Add(c, c-'0'); } numbers.Add('A', 1); numbers.Add('T', 10); numbers.Add('J', 11); numbers.Add('Q', 12); numbers.Add('K', 13); } #region IComparer implementation int IComparer.Compare (string x, string y) { if (orders [x [0]] == orders [y [0]]) { return numbers[x[1]] - numbers[y[1]]; } return orders[x[0]] - orders[y[0]]; } #endregion } public static void Main (string[] args) { var n = Console.ReadLine (); var keys = Console.ReadLine ().Split(' ').ToList(); keys.Sort (new CustomComparer ()); Console.WriteLine(string.Join(" ", keys)); } } }