結果

問題 No.267 トランプソート
ユーザー くれちーくれちー
提出日時 2017-02-04 22:40:43
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,352 bytes
コンパイル時間 7,576 ms
コンパイル使用メモリ 173,416 KB
実行使用メモリ 6,960 KB
最終ジャッジ日時 2023-08-25 20:19:35
合計ジャッジ時間 6,631 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,620 KB
testcase_01 AC 3 ms
6,616 KB
testcase_02 AC 3 ms
6,732 KB
testcase_03 AC 3 ms
6,652 KB
testcase_04 AC 3 ms
6,716 KB
testcase_05 AC 3 ms
6,724 KB
testcase_06 AC 3 ms
6,680 KB
testcase_07 AC 2 ms
6,712 KB
testcase_08 AC 3 ms
6,860 KB
testcase_09 AC 2 ms
6,840 KB
testcase_10 AC 3 ms
6,764 KB
testcase_11 AC 3 ms
6,824 KB
testcase_12 AC 2 ms
6,824 KB
testcase_13 AC 2 ms
6,876 KB
testcase_14 AC 2 ms
6,760 KB
testcase_15 AC 3 ms
6,752 KB
testcase_16 AC 3 ms
6,924 KB
testcase_17 AC 2 ms
6,772 KB
testcase_18 AC 2 ms
6,772 KB
testcase_19 AC 2 ms
6,776 KB
testcase_20 AC 3 ms
6,764 KB
testcase_21 AC 2 ms
6,960 KB
testcase_22 AC 2 ms
6,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Char (ord)
import Data.List (sort)
import Control.Applicative ((<$>))

data Rank = A | Rank Int | T | J | Q | K
    deriving (Eq, Ord)

instance Read Rank where
    readsPrec _ s = readRank s

readRank :: ReadS Rank
readRank ('A':s) = [(A, s)]
readRank ('T':s) = [(T, s)]
readRank ('J':s) = [(J, s)]
readRank ('Q':s) = [(Q, s)]
readRank ('K':s) = [(K, s)]
readRank (c:s)   = [(x, s)]
    where
        x = Rank $ ord c - ord '0'

instance Show Rank where
    show (Rank x) = show x
    show A        = "A"
    show T        = "T"
    show J        = "J"
    show Q        = "Q"
    show K        = "K"

data Suit = D | C | H | S
    deriving (Eq, Ord, Show)

instance Read Suit where
    readsPrec _ s = readSuit s

readSuit :: ReadS Suit
readSuit ('D':s) = [(D, s)]
readSuit ('C':s) = [(C, s)]
readSuit ('H':s) = [(H, s)]
readSuit ('S':s) = [(S, s)]

data Card = Card Suit Rank
    deriving (Eq, Ord)

instance Read Card where
    readsPrec _ s = readCard s

readCard :: ReadS Card
readCard "" = []
readCard s = [(Card suit rank, c2)]
    where
        [(suit, c1)] = readSuit s
        [(rank, c2)] = readRank c1

instance Show Card where
    show (Card suit rank) = show suit ++ show rank

solve :: [Card] -> String
solve = unwords . (map show) . sort

main = do
    getLine
    cs <- map read . words <$> getLine
    putStrLn $ solve cs
0