[Haskell-beginners] Sorting Bank Accounts problem in Haskell
dav.vire+haskell at gmail.com
Wed Aug 14 12:17:48 CEST 2013
You should probably start by switching strings to Data.Text.
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
> 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
> 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
More information about the Beginners