using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; this.InitDic(); int itemCount = int.Parse(Reader.ReadLine()); List ans = Reader.ReadLine().Split(' ').ToList(); ans.Sort((a,b)=>{ if(markDic[a[0]] < markDic[b[0]]) { return -1; } else if(markDic[a[0]] > markDic[b[0]]) { return 1; } else if(numDic[a[1]] < numDic[b[1]]) { return -1; } else if(numDic[a[1]] > numDic[b[1]]) { return 1; } return 0; }); Console.WriteLine(string.Join(" ", ans)); } private Dictionary numDic = new Dictionary(); private Dictionary markDic = new Dictionary(); private void InitDic() { numDic.Add('A', 1); for(int i=2; i<=9; i++) { numDic.Add(i.ToString()[0], i); } numDic.Add('T', 10); numDic.Add('J', 11); numDic.Add('Q', 12); numDic.Add('K', 13); markDic.Add('D',1); markDic.Add('C',2); markDic.Add('H',3); markDic.Add('S',4); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 6 S4 SA C5 C4 CA DA "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }