Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save msysyamamoto/11387260 to your computer and use it in GitHub Desktop.

Select an option

Save msysyamamoto/11387260 to your computer and use it in GitHub Desktop.
import Control.Applicative ((<$>))
import Data.Char (ord)
main :: IO ()
main = do
ws <- lines' <$> getContents
mapM_ putStrLn $ solve ws
solve :: [String] -> [String]
solve ws = do
w <- ws
return . maybe (glue w "X") (glue w) $ spacetalky w
where
glue xs ys = ys ++ ":" ++ xs
spacetalky :: String -> Maybe String
spacetalky output
| odd $ length output = Nothing
| otherwise = go output
where
len x = ord x - ord 'a' + 1
go (x0:x1:x2:xs)
| x0 == x2 && x1 /= 'z' = Nothing
| otherwise = do
enc <- go (x2:xs)
Just $ take (len x1) (repeat x0) ++ enc
go [x0, x1] = Just $ take (len x1) (repeat x0)
go _ = Nothing -- ここには来ないはず
-- "\r\n" 用
lines' :: String -> [String]
lines' = lines . filter (/= '\r')
@msysyamamoto
Copy link
Author

始めのバージョンは不正解だったので修正した。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment