Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solution to the Google Code Jam Qualification Round Problem #1
import Control.Monad
getA :: [Char] -> [Char]
getA n = map (\x -> if x == '4' then '2' else '0') n
getB :: [Char] -> [Char]
getB n = map (\x -> if x == '4' then '2' else x) n
solveCase :: [Char] -> (String, String)
solveCase n = (getA n, getB n)
caseSolutionString :: (Int, [Char]) -> String
caseSolutionString (i, n) = "Case #" ++ show i ++ ": " ++ fst sol ++ " " ++ snd sol
where sol = solveCase n
readCase :: Int -> IO (Int, String)
readCase i = do
nstr <- getLine
return (i, takeWhile (\c -> (c /= '\r') && (c /= '\n')) nstr)
main = do
t <- getLine
let tn = (read t) :: Int
cases <- forM [1..tn] readCase
mapM putStrLn (map caseSolutionString cases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.