結果

問題 No.39 桁の数字を入れ替え
コンテスト
ユーザー vain0
提出日時 2015-07-25 14:18:09
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 626 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,961 ms
コンパイル使用メモリ 194,432 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-30 19:13:33
合計ジャッジ時間 1,834 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
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: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 #
raw source code

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