首页 > 代码库 > hackerrank--- challenges/fp-update-list

hackerrank--- challenges/fp-update-list

纯属为了练习haskell, 竟然贴代码都没办法高亮。

challenges/fp-update-list

Update the values of a list with their absolute values. The input and output portions will be handled automatically during grading. You only need to write a function with the recommended method signature.

Input Format 
There are N integers, each on a new line. These are the N elements of the input array.

Output Format 
N integers each on a new line; these are the absolute values of the input list, in that order.

Sample Input

2-43-123-4-54

Sample Output

243123454

Accpeted Code:

1 -- Enter your code here. Read input from STDIN. Print output to STDOUT2 3 f arr = [if x >= 0 then x else -x | x <- arr] -- Complete this function here4 5 -- This section handles the Input/Output and can be used as it is. Do not modify it.6 main = do7    inputdata <- getContents8    mapM_ putStrLn $ map show $ f $ map (read :: String -> Int) $ lines inputdata