Created
March 24, 2012 13:21
-
-
Save dekosuke/2182727 to your computer and use it in GitHub Desktop.
Answer of FASHION at SPOJ
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 Data.List | |
import Data.Int | |
import Data.Char | |
type Z = Int | |
myMapReadWords :: String -> [Z] | |
myMapReadWords ('1':'0':' ':rest) = 10 : myMapReadWords rest | |
myMapReadWords ('1':'0':[]) = 10 : [] | |
myMapReadWords (a:' ':rest) = digitToInt a : myMapReadWords rest | |
myMapReadWords (a:[]) = digitToInt a : [] | |
solve input = | |
unlines $ solveProblems problems | |
where | |
ls = lines input | |
n = (read $ head ls)::Z | |
getProblems [] = [] | |
getProblems (n:ms:ws:rest) = | |
(myMapReadWords ms, myMapReadWords ws) : getProblems rest | |
problems = (getProblems $ tail ls) :: [([Z], [Z])] | |
solveProblem (ms,ws) = | |
sum $ map (\(a,b)->a*b) $ zip (sort ms) (sort ws) | |
solveProblems = map (show.solveProblem) | |
main = interact solve |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
myMapReadWords = map read $ words , much faster implementation