using System; namespace Csharp { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); string[] Serials = new string[N]; for (int i = 0; i < N; i++) { Serials[i] = Console.ReadLine(); } Array.Sort(Serials, (lhs, rhs) => { int lsum = Cal(lhs), rsum = Cal(rhs); int leftLen = lhs.Length, rightLen = rhs.Length; if (leftLen == rightLen && lsum == rsum) return lhs.CompareTo(rhs); if (leftLen == rightLen) return lsum.CompareTo(rsum); return leftLen.CompareTo(rightLen); }); for (int i = 0; i < N; i++) Console.WriteLine(Serials[i]); } static int Cal(string str) { int result = 0; for (int i = 0; i < str.Length; i++) { if (Char.IsDigit(str[i])) result += str[i] - '0'; } return result; } } } |