Codeforces 3A - A. Shortest path of the king
3A - A. Shortest path of the king
import Data.Char parse :: String -> (Int, Int) parse s = (digitToInt (s!!1), ord (s!!0) - ord 'a' + 1) calc :: (Int, Int) -> (Int, Int) -> [String] calc (sr, sc) (dr, dc) | sr == dr && sc == dc = [] | otherwise = dir : calc (r, c) (dr, dc) where r = sr + signum (dr - sr) c = sc + signum (dc - sc) dir = (move sc dc "R" "L") ++ (move sr dr "U" "D") move src dst lt gt | src == dst = "" | src < dst = lt | otherwise = gt main :: IO () main = do s <- getLine t <- getLine let moves = calc (parse s) (parse t) print $ length moves mapM_ putStrLn moves
mapM_ はまだよく意味が分かっていない。
参考: