結果

問題 No.39 桁の数字を入れ替え
ユーザー はむ吉🐹はむ吉🐹
提出日時 2015-12-30 17:26:44
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 702 bytes
コンパイル時間 8,563 ms
コンパイル使用メモリ 166,292 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-10-19 12:41:23
合計ジャッジ時間 8,035 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,200 KB
testcase_01 AC 3 ms
5,200 KB
testcase_02 AC 2 ms
5,212 KB
testcase_03 AC 2 ms
5,224 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,276 KB
testcase_06 AC 2 ms
5,316 KB
testcase_07 AC 2 ms
5,364 KB
testcase_08 WA -
testcase_09 AC 3 ms
5,424 KB
testcase_10 AC 3 ms
5,224 KB
testcase_11 AC 2 ms
5,316 KB
testcase_12 AC 3 ms
5,316 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 2 ms
5,248 KB
testcase_15 AC 2 ms
5,212 KB
testcase_16 AC 2 ms
5,224 KB
testcase_17 AC 3 ms
5,224 KB
testcase_18 AC 2 ms
5,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

-- 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
0