Skip to content

Instantly share code, notes, and snippets.

@Abizern
Created October 31, 2012 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Abizern/3986006 to your computer and use it in GitHub Desktop.
Save Abizern/3986006 to your computer and use it in GitHub Desktop.
A better solution to the Google Code Jam problem "Reverse Words"
module Main where
{-
Problem statement:
http://code.google.com/codejam/contest/351101/dashboard#s=p1
Run as a script with runghc, or compile with ghc --make -O2
input and output is by redirection;
$ ./reverse_words < input_file > output_file
-}
import Control.Monad
main :: IO ()
main = do
n <- readLn
forM_ [1..n] $ \i -> do
solution <- fmap (unwords . reverse . words) getLine
putStrLn $ "Case #" ++ show i ++ ": " ++ solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment