Created
April 11, 2019 09:30
-
-
Save RationalAsh/b92dfab3970e5d9ba2b4855afedf0d5c to your computer and use it in GitHub Desktop.
Solution to the Google Code Jam Qualification Round Problem #1
This file contains 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.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