[Haskell-beginners] Sorting Bank Accounts problem in Haskell
Nadav Chernin
nadavchernin at gmail.com
Tue Aug 13 17:05:15 CEST 2013
Hi all,
I learn Haskell and i try to solve questions from SPOJ.
Currently, i try to solve problem *Sorting Bank
Accounts*<http://www.spoj.com/problems/SBANK/>
Here is my code:
*import qualified Data.Map as M*
*
*
*extractTest []=[]*
*extractTest (x:xs)=(take n xs):(extractTest (drop (n+1) xs)) where*
* n=read x*
*
*
*emp=M.empty*
*
*
*collect m []=m*
*collect m (x:xs)*
* |M.member x m =collect (M.insert x (amount+1) m) xs*
* |otherwise=collect (M.insert x 1 m) xs*
* where*
* Just amount=M.lookup x m*
*
*
*getList m=map (\(x,k)->x++" "++(show k)) (M.toList m)*
*f x=unlines$(getList (collect emp x))++[""]*
*main=getLine>>=(\x->interact$unlines.map f.take (read x).extractTest.lines)
*
*
*
The problem is that i can't finish it during 7 sec.
So i want to know is there more quick solution/method for this problem.
Thanks, Nadav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130813/fd75d889/attachment.htm>
More information about the Beginners
mailing list