mapping = Struct.new(:index, :value) n = gets.to_i t = gets.split m = Array.new(n) n.times do |i| value = 0 if t[i][0] == "D" value += 0 elsif t[i][0] == "C" value += 13 elsif t[i][0] == "H" value += 13 * 2 else value += 13 * 3 end if t[i][1] == "A" value += 1 elsif t[i][1] == "T" value += 10 elsif t[i][1] == "J" value += 11 elsif t[i][1] == "Q" value += 12 elsif t[i][1] == "K" value += 13 else value += t[i][1].to_i end m[i] = mapping.new(i, value) end m.sort! { |a, b| a.value <=> b.value } m.length.times do |i| if i >= m.length - 1 puts t[m[i].index] break end print t[m[i].index], " " end