using System.Collections.Generic; using System.Linq; using System; public class P { public int m2 { get; set; } public string m { get; set; } public int na { get; set; } } public class Hello { public static void Main() { var m = new char[] { 'D', 'C', 'H', 'S', 'A', 'T', 'J', 'Q', 'K' }; var m2 = new int[] { 0, 1, 2, 3, 1, 10, 11, 12, 13 }; var d = new Dictionary(); for (int i = 0; i < 9; i++) d[m[i]] = m2[i]; var n = int.Parse(Console.ReadLine().Trim()); string[] s = Console.ReadLine().Trim().Split(' '); var ps = new P[n]; for (int i = 0; i < n; i++) { int w; if (d.ContainsKey(s[i][1])) w = d[s[i][1]]; else w = int.Parse(s[i][1].ToString()); ps[i] = new P { m = s[i], m2 = d[s[i][0]], na = w }; } Console.WriteLine(string.Join(" ", ps.OrderBy(y => y.m2).ThenBy(y => y.na).Select(y => y.m))); } }