第18回オフラインリアルタイムどう書くの参考問題をHaskellで解いた
第18回オフラインリアルタイムどう書くの参考問題をHaskellで解きました。
問題の詳細は山折り谷折り〜 横へな 2014.2.1 参考問題
yamatani.hs
invert [] = []
invert xs = map invert' $ reverse xs
where
invert' 'm' = 'V'
invert' 'V' = 'm'
j [] = "V"
j xs = xs ++ "V" ++ (invert xs)
l [] = "V"
l xs = (invert xs) ++ "V" ++ xs
s [] = "Vm"
s xs = xs ++ "V" ++ (invert xs) ++ "m" ++ xs
z [] = "mV"
z xs = xs ++ "m" ++ (invert xs) ++ "V" ++ xs
u [] = "VV"
u xs = (invert xs) ++ "V" ++ xs ++ "V" ++ (invert xs)
solve xs = foldr applyFunc "" xs
where
applyFunc :: Char -> String -> String
applyFunc c xs = charToFunc c xs
charToFunc :: Char -> (String -> String)
charToFunc 'J' = j
charToFunc 'L' = l
charToFunc 'S' = s
charToFunc 'Z' = z
charToFunc 'U' = u
main = do
line <- getLine
let [input, expect] = words line
let output = solve input
putStrLn $ if expect == output then "OK" else "NG"
main
他の過去問も解いています。(解けそうな問題から書いてます。。。汗)
Author And Source
この問題について(第18回オフラインリアルタイムどう書くの参考問題をHaskellで解いた), 我々は、より多くの情報をここで見つけました https://qiita.com/liveinwood/items/d5fe7ce141ec8ac01a45著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .