結果

問題 No.39 桁の数字を入れ替え
ユーザー vain0vain0
提出日時 2015-07-25 14:26:21
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 549 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 163,188 KB
実行使用メモリ 6,892 KB
最終ジャッジ日時 2023-09-23 04:55:02
合計ジャッジ時間 2,065 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,844 KB
testcase_01 AC 2 ms
6,640 KB
testcase_02 AC 3 ms
6,656 KB
testcase_03 AC 3 ms
6,724 KB
testcase_04 AC 3 ms
6,724 KB
testcase_05 AC 2 ms
6,728 KB
testcase_06 AC 2 ms
6,696 KB
testcase_07 AC 3 ms
6,708 KB
testcase_08 AC 2 ms
6,764 KB
testcase_09 AC 3 ms
6,648 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 3 ms
6,700 KB
testcase_15 AC 2 ms
6,672 KB
testcase_16 AC 3 ms
6,744 KB
testcase_17 AC 3 ms
6,700 KB
testcase_18 AC 2 ms
6,724 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 )

Main.hs:9:1: warning: [GHC-94817] [-Wtabs]
    Tab character found here, and in 23 further locations.
    Suggested fix: Please use spaces instead.
  |
9 |         where f (x, xi) (m, mi) = if x > m then (x, xi) else (m, mi)
  | ^^^^^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import qualified Data.Char as Char
import qualified Data.List as List
import Data.Array
import Data.Maybe
import Control.Applicative
import Text.Printf

max_index_r xs = foldr1 f (zip xs [0..])
	where f (x, xi) (m, mi) = if x > m then (x, xi) else (m, mi)

iter_swap i j xs =
	map f (zip xs [0..])
	where
		f (x, k)
			| k == i    = xs !! j
			| k == j    = xs !! i
			| otherwise = x

main = do
	ns <- getLine
	let (ma, i) = max_index_r ns
	let ns' =
		case List.findIndex (/= ma) ns of
		Just j | i > j -> iter_swap i j ns
		_ -> ns
	putStrLn ns'
0