0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

第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

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?