結果

問題 No.267 トランプソート
ユーザー くれちー
提出日時 2017-02-04 22:40:43
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,352 bytes
コンパイル時間 4,134 ms
コンパイル使用メモリ 184,704 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 06:24:45
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/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