Help us understand the problem. What is going on with this article?

第18回オフラインリアルタイムどう書くの参考問題をHaskellで解いた

More than 5 years have passed since last update.

第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

他の過去問も解いています。(解けそうな問題から書いてます。。。汗)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away