結果

問題 No.39 桁の数字を入れ替え
ユーザー vain0vain0
提出日時 2015-07-25 14:18:09
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 626 bytes
コンパイル時間 8,838 ms
コンパイル使用メモリ 161,064 KB
実行使用メモリ 6,772 KB
最終ジャッジ日時 2023-09-23 04:54:09
合計ジャッジ時間 9,065 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,656 KB
testcase_01 AC 2 ms
6,636 KB
testcase_02 AC 2 ms
6,592 KB
testcase_03 AC 3 ms
6,660 KB
testcase_04 AC 2 ms
6,636 KB
testcase_05 AC 2 ms
6,604 KB
testcase_06 WA -
testcase_07 AC 3 ms
6,640 KB
testcase_08 AC 2 ms
6,624 KB
testcase_09 AC 3 ms
6,736 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
6,660 KB
testcase_15 AC 2 ms
6,624 KB
testcase_16 AC 2 ms
6,600 KB
testcase_17 AC 3 ms
6,532 KB
testcase_18 AC 3 ms
6,612 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 18 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)

min_index_l xs = foldl1 f (zip xs [0..])
	where f (m, mi) (x, xi) = 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 i = snd $ min_index_l ns
	let j = snd $ max_index_r ns
	putStrLn $ if i < j then iter_swap i j ns else ns
0