結果

問題 No.267 トランプソート
ユーザー gemmarogemmaro
提出日時 2020-08-15 08:08:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 820 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-18 23:43:45
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,160 KB
testcase_01 AC 83 ms
12,288 KB
testcase_02 AC 84 ms
12,288 KB
testcase_03 AC 78 ms
12,160 KB
testcase_04 AC 82 ms
12,288 KB
testcase_05 AC 82 ms
12,160 KB
testcase_06 AC 83 ms
12,288 KB
testcase_07 AC 84 ms
12,288 KB
testcase_08 AC 84 ms
12,160 KB
testcase_09 AC 82 ms
12,160 KB
testcase_10 AC 82 ms
12,416 KB
testcase_11 AC 82 ms
12,288 KB
testcase_12 AC 81 ms
12,160 KB
testcase_13 AC 77 ms
12,416 KB
testcase_14 AC 78 ms
12,160 KB
testcase_15 AC 82 ms
12,160 KB
testcase_16 AC 82 ms
12,160 KB
testcase_17 AC 83 ms
12,416 KB
testcase_18 AC 82 ms
12,416 KB
testcase_19 AC 81 ms
12,416 KB
testcase_20 AC 84 ms
12,160 KB
testcase_21 AC 81 ms
12,160 KB
testcase_22 AC 77 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

Card = Struct.new(:to_s, :mark, :number)

class String
  def to_card
    mark = case self[0]
           when 'D' then 0
           when 'C' then 1
           when 'H' then 2
           when 'S' then 3
           end
    number = case self[1]
             when 'A' then 1
             when 'T' then 10
             when 'J' then 11
             when 'Q' then 12
             when 'K' then 13
             else self[1].to_i
             end
    Card.new(self, mark, number)
  end
end

def solve
  MN.map(&:to_card)
    .group_by { _1.mark }
    .map { |k, v| { k => v.sort { |a, b| a.number <=> b.number } } }
    .reduce(:merge)
    .to_a
    .sort { |a, b| a[0] <=> b[0] }
    .map { _1[1] }
    .flatten
    .map(&:to_s)
    .join(" ")
end

N = gets.to_i
MN = gets.chomp.split

puts solve
0