首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。