結果
| 問題 | No.267 トランプソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-21 04:27:46 |
| 言語 | Standard ML (MLton 20241230) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,770 bytes |
| 記録 | |
| コンパイル時間 | 6,548 ms |
| コンパイル使用メモリ | 708,968 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-21 04:27:56 |
| 合計ジャッジ時間 | 3,271 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
コンパイルメッセージ
Warning: main.sml 25.5-28.22.
Function is not exhaustive.
missing pattern: #"\^@" .. #"B"
| #"E"
| #"F"
| #"G"
| #"I" .. #"R"
| #"T" .. #"\255"
in: fun markToInt #"D" = 0 | markToIn ... | markToInt #"S" = 3
Warning: main.sml 44.5-47.21.
Function is not exhaustive.
missing pattern: ~2147483648 .. ~1 | 4 .. 2147483647
in: fun intToMark 0 = "D" | intToMark ... | intToMark 3 = "S"
ソースコード
fun readInt () =
valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)
fun readStr () =
let
fun scan reader stream = SOME (StringCvt.splitl (not o Char.isSpace) reader (StringCvt.skipWS reader stream))
in
valOf (TextIO.scanStream scan TextIO.stdIn)
end
fun quicksort [] = []
| quicksort (h::tl) =
let
val (s, b) =
List.foldl
(fn (x, (small, big)) =>
if x <= h then (x::small, big)
else (small, x::big))
([], [])
tl
in
(quicksort s) @ [h] @ (quicksort b)
end
fun markToInt #"D" = 0
| markToInt #"C" = 1
| markToInt #"H" = 2
| markToInt #"S" = 3
fun charToInt #"A" = 1
| charToInt #"T" = 10
| charToInt #"J" = 11
| charToInt #"Q" = 12
| charToInt #"K" = 13
| charToInt ch = Char.ord ch - Char.ord #"0"
fun cardsToInts [] = []
| cardsToInts (h::tl) =
(markToInt (String.sub (h, 0)) * 13 + charToInt (String.sub (h, 1)) - 1) ::
cardsToInts tl
fun intToMark 0 = "D"
| intToMark 1 = "C"
| intToMark 2 = "H"
| intToMark 3 = "S"
fun intToCardValue 1 = "A"
| intToCardValue 10 = "T"
| intToCardValue 11 = "J"
| intToCardValue 12 = "Q"
| intToCardValue 13 = "K"
| intToCardValue n =
Int.toString n
fun intsToCards [] = []
| intsToCards (h::tl) =
(intToMark (h div 13) ^ intToCardValue ((h mod 13) + 1)) ::
intsToCards tl
val () =
let
val n = readInt ()
val cards = List.tabulate (n, fn _ => readStr ())
val ints = cardsToInts cards
val sorted = quicksort ints
val sortedCards = intsToCards sorted
val ans = String.concatWith " " sortedCards
in
print (ans ^ "\n")
end