Admins
Kindly have a look at submission ID 5137590 and tell me why its getting runtime error. I think there is some problem with String because one of my other solution for Street Parade STPAR in Haskell is also getting run time error but both of these solutions run perfectly fine on my system.
Thank you
import Data.List
--import qualified Data.ByteString.Char8 as BS
convert ::[[String]]->[(Int , String)]
convert [] = []
convert ( x:xs ) = (read x_1 , ys ) : convert xs where
(x_1:ys:_) = x
toString ::[(Int,String)] -> String
toString [(_,y)] = y
toString (x:xs) = y ++ "\n" ++ toString xs where
(_,y) = x
solve::Int -> [String]->[String]
solve _ [] = []
solve t xs = [ "Case #"++show t ++":\n"++ ans ] ++ solve ( t+1 ) ys where
(x,ys) = splitAt 10 xs
xs' = sortBy (\( a, _ ) ( b, _ ) -> compare b a ). convert . map ( reverse.words ) $ x
m = fst.head $ xs'
ans' = takeWhile ( \( a , b ) -> a == m ) xs'
ans = toString ans'
main = interact $ unlines. solve 1 .tail . lines
created
last reply
- 4
replies
- 645
views
- 2
users
- 1
link