a = [] 3.times do |i| a << [i] + gets.split.map(&:to_i) end a.sort_by!{|x| [-x[1], x[2]]} a.each do |i| puts ( case i[0] when 0 'A' when 1 'B' when 2 'C' end ) end