関数型プログラミング言語Haskell Part30at TECH
関数型プログラミング言語Haskell Part30 - 暇つぶし2ch10:デフォルトの名無しさん
17/01/16 21:52:49.11 e08JNJ9T.net
前スレで質問しようとして何か変な風に失敗してしまいました...
再掲させてください
----
aojの問題でわからないところがあるので質問します.
URLリンク(judge.u-aizu.ac.jp)
二股にわかれた容器に1から10まで番号のついたボールを番号の大小関係の制約を守って並べていけるかを判定する問題なんですが,自分のコードを提出するとruntime errorになってしまいます.
理由も考えたんですがよくわからないので,何がダメなのかアドバイスをお願いしたいです.

main :: IO ()
main = getContents >>= mapM_ (putStrLn . (\arr -> solve (tail arr) 0 (head arr, 0)) . map (read :: String -> Int) . words) . tail . lines
solve :: [Int] -> Int -> (Int, Int) -> String
solve arr index (box1, box2)
| index == length arr = "YES"
| otherwise =
if box1 < box2 then
solve arr index (box2, box1)
else
if arr !! index > box1 then
solve arr (index + 1) (arr !! index, box2)
else
if arr !! index > box2 then
solve arr (index + 1) (box1, arr !! index)
else
"NO"


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch