纯属为了练习haskell, 竟然贴代码都没办法高亮。
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 -4 3 -1 23 -4 -54
Sample Output
2 4 3 1 23 4 54
Accpeted Code:
1 -- Enter your code here. Read input from STDIN. Print output to STDOUT
2
3 f arr = [if x >= 0 then x else -x | x <- arr] -- Complete this function here
4
5 -- This section handles the Input/Output and can be used as it is. Do not modify it.
6 main = do
7 inputdata <- getContents
8 mapM_ putStrLn $ map show $ f $ map (read :: String -> Int) $ lines inputdata