結果
| 問題 |
No.267 トランプソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-15 08:08:26 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 87 ms / 1,000 ms |
| コード長 | 820 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-10-10 17:16:29 |
| 合計ジャッジ時間 | 3,936 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
コンパイルメッセージ
Syntax OK
ソースコード
# 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