結果
| 問題 |
No.39 桁の数字を入れ替え
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2015-12-30 17:26:44 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 702 bytes |
| コンパイル時間 | 5,124 ms |
| コンパイル使用メモリ | 171,264 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 08:47:24 |
| 合計ジャッジ時間 | 2,748 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 1 |
コンパイルメッセージ
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
ソースコード
-- Based on http://stackoverflow.com/questions/30551033/swap-two-elements-in-a-list-by-its-indices
swapElementsAt :: Int -> Int -> [a] -> [a]
swapElementsAt i j xs = left ++ [elemJ] ++ middle ++ [elemI] ++ right
where
elemI = (!!) xs $ min i j
elemJ = (!!) xs $ max i j
left = take i xs
middle = take (j - i - 1) $ flip drop xs $ i + 1
right = flip drop xs $ j + 1
swapDigitsAt :: Int -> Int -> Int -> Int
swapDigitsAt i j = read . swapElementsAt i j . show
getMaximum :: Int -> Int
getMaximum n = maximum [swapDigitsAt i j n | j <- [1 .. l - 1], i <- [0 .. j - 1]]
where
l = length $ show n
main :: IO ()
main = print . getMaximum =<< readLn
はむ吉🐹