[Haskell-beginners] Sorting Bank Accounts problem in Haskell

David Virebayre dav.vire+haskell at gmail.com
Wed Aug 14 12:17:48 CEST 2013


You should probably start by switching strings to Data.Text.

David.

2013/8/13 Nadav Chernin <nadavchernin at gmail.com>:
> Hi all,
> I learn Haskell and i try to solve questions from SPOJ.
>
> Currently, i try to solve problem Sorting Bank Accounts
>
> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>




More information about the Beginners mailing list