fork(1) download
  1. -- Solution for https://g...content-available-to-author-only...b.com/draftcode/coding-interview/blob/master/aggregate.md
  2.  
  3. import qualified Data.Map as M
  4. import GHC.Exts
  5.  
  6. = map (\(n,v) -> n ++ " " ++ (show v))
  7. 野 dict = reverse $ sortWith snd (M.toList dict)
  8. 梓 lst = foldl にゃん M.empty $ map words lst
  9. where
  10. にゃん dict (name:val:_) = M.insertWith (+) name (read val) dict
  11.  
  12. あずにゃん =..
  13.  
  14. main = interact (unlines . (あずにゃん . lines))
Success #stdin #stdout 0s 6312KB
stdin
Apple 3
Banana 5
Melon 2
Apple 8
Melon 4
stdout
Apple 11
Melon 6
Banana 5