Submission #308772
Source Code Expand
import Control.Applicative import Data.List main = do str <- getContents let times = tail $ lines str let pairs = sortBy f $ map mkpair times print_loop $ sortBy f $ loop pairs [] mkpair str = (normalize (kirisage st), normalize (kiriage ed)) where [st, ed] = map read $ [take 4 str, drop 5 str] normalize n = if drop 2 (show n) == "60" then n - 60 + 100 else n kiriage n = if n `mod` 5 == 0 then n else n + (5 - n `mod` 5) kirisage n = if n `mod` 5 == 0 then n else n - (n `mod` 5) myprint n = putStr $ replicate (4 - length s) '0' ++ s where s = show n loop [] acc = acc loop ((st, ed) : rest) acc = loop rest (update st ed acc) update st ed acc = f r where r = find (\(a, b) -> st <= b) acc f Nothing = acc ++ [(st,ed)] f (Just (a,b)) = sortBy f $ (a, max b ed) : delete (a,b) acc print_loop [] = return () print_loop ((st, ed) : rest) = do myprint st putStr "-" myprint ed putStrLn "" print_loop rest f (a, _) (b, _) | a < b = LT | a > b = GT | otherwise = EQ
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | lambdataro |
Language | Haskell (GHC 7.4.1) |
Score | 0 |
Code Size | 1093 Byte |
Status | CE |
Compile Error
Main.hs:37:33: Couldn't match expected type `Maybe (t0, t1) -> Ordering' with actual type `[(t2, t3)]' Expected type: Maybe (t0, t1) -> Maybe (t0, t1) -> Ordering Actual type: Maybe (t0, t1) -> [(t2, t3)] In the first argument of `sortBy', namely `f' In the expression: sortBy f