首页 > 其他 > 详细

hackerrank--- challenges/fp-update-list

时间:2014-06-21 11:41:32      阅读:294      评论:0      收藏:0      [点我收藏+]

纯属为了练习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
-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

 

hackerrank--- challenges/fp-update-list,布布扣,bubuko.com

hackerrank--- challenges/fp-update-list

原文:http://www.cnblogs.com/Stomach-ache/p/3794952.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!