Last active
August 29, 2015 14:00
-
-
Save msysyamamoto/11387260 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
始めのバージョンは不正解だったので修正した。