結果

問題 No.267 トランプソート
コンテスト
ユーザー aimy
提出日時 2017-04-25 19:36:39
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 513 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 942 ms
コンパイル使用メモリ 193,664 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 04:24:06
合計ジャッジ時間 1,646 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_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:14:106: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, but defined in GHC.Internal.List):
    "This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
   |
14 | main = getContents >>= putStrLn . unwords . map show . sort . map (\[s,n] -> Card {suit = s, num = n}) . tail . words
   |                                                                                                          ^^^^

[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import Data.List

data Trump = Card {suit :: Char, num :: Char} deriving Eq

instance Ord Trump where
 c1 <= c2 = scomp (suit c1) (suit c2) || ((suit c1) == (suit c2) && ncomp (num c1) (num c2))
  where
   scomp s1 s2 = elemIndex s1 "DCHS" < elemIndex s2 "DCHS"
   ncomp n1 n2 = elemIndex n1 "A23456789TJQK" <= elemIndex n2 "A23456789TJQK"
  
instance Show Trump where
 show c = [suit c, num c]

main = getContents >>= putStrLn . unwords . map show . sort . map (\[s,n] -> Card {suit = s, num = n}) . tail . words
0