結果

問題 No.267 トランプソート
コンテスト
ユーザー Haar
提出日時 2016-06-17 20:38:27
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 753 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,599 ms
コンパイル使用メモリ 190,848 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2026-04-25 20:52:18
合計ジャッジ時間 5,670 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:13:1: warning: [GHC-94817] [-Wtabs]
    Tab character found here, and in 8 further locations.
    Suggested fix: Please use spaces instead.
   |
13 |         | and (map isDigit str) = read str
   | ^^^^^^^^

[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import Data.List(sortBy)
import Data.Char(isDigit)

data Mark = D | C | H | S deriving (Show, Enum, Read)

toNum :: String -> Int
toNum "A" = 1
toNum "T" = 10
toNum "J" = 11
toNum "Q" = 12
toNum "K" = 13
toNum str
	| and (map isDigit str) = read str
	| otherwise = 0

fromNum :: Int -> String
fromNum 1 = "A"
fromNum 10 = "T"
fromNum 11 = "J"
fromNum 12 = "Q"
fromNum 13 = "K"
fromNum x = show x

comp :: (Mark, Int) -> (Mark, Int) -> Ordering
comp (ma, a) (mb, b)
	| c /= EQ = c
	| otherwise = compare a b
	where c = compare (fromEnum ma) (fromEnum mb)

main = do
	getLine
	cards <- return . unwords . map (\(m, n) -> show m ++ fromNum n) . sortBy comp . map ((\(m, n) -> (read m :: Mark, toNum n)) . (splitAt 1)) . words =<< getLine
	
	putStrLn cards
0