Created
March 27, 2012 20:05
-
-
Save dradtke/2219778 to your computer and use it in GitHub Desktop.
Haskell Solution for Reverse Words (Google Code Jam)
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
| data Unsolved = Unsolved { unsolvedNumber :: Int, input :: String } | |
| data Solved = Solved { solvedNumber :: Int, answer :: String } | |
| instance Show Solved where | |
| show (Solved n ans) = "Case #" ++ (show n) ++ ": " ++ ans | |
| main :: IO () | |
| main = do | |
| input <- fmap lines getContents | |
| let input' = tail input | |
| let cases = zipWith Unsolved [1..] input' | |
| mapM_ putStrLn $ map (show.solve) cases | |
| solve :: Unsolved -> Solved | |
| solve (Unsolved n input) = Solved n ans | |
| where ans = (unwords.reverse.words) input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment