1 / 5
May 2011

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

    May '11
  • last reply

    May '11
  • 4

    replies

  • 645

    views

  • 2

    users

  • 1

    link

I rewrote the above Haskell solution in c++ and accepted so i think there is some thing wrong with Haskell for this problem. Admins kindly have a look into the issue.
Thank you

Your code does not compile. I do not think that you pasted the code as is.
Also note that there are some accepted solutions to this problem in Haskell, so the problem may lie in your code.

I think this code should compile. I will try to rewrite it again .
Thank you for reply.

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

It compiles. If I change your code so that it does not rely on the end of file, it is accepted. Therefore, I guess that the test input contains some garbage after the legitimate input.