gets cards = gets.chomp.split mark_priority = {'D' => 1, 'C' => 2, 'H' => 3, 'S' => 4} number_priority = {'A' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'T' => 10, 'J' => 11, 'Q' => 12, 'K' => 13} cards.sort! { |a, b| mark_priority[a.split('')[0]] <=> mark_priority[b.split('')[0]]} cards.sort! { |a, b| number_priority[a.split('')[1]] <=> number_priority[b.split('')[1]] } cards.each { |e| print e << ' '} puts ''