Skip to content

Instantly share code, notes, and snippets.

@jkramer jkramer/mime.hs
Created Jan 11, 2016

Embed
What would you like to do?
CodinGame - MIME Type
import Control.Monad
import Data.Char
import Data.Maybe
import Data.List
main = do
[n, q] <- replicateM 2 (fmap read getLine)
types <- replicateM n (fmap ((\ [x, y] -> (map toLower x, y)) . words) getLine)
replicateM q $ do
ext <- fmap (extension . map toLower) getLine
putStrLn (fromMaybe "UNKNOWN" (lookup ext types))
extension s =
if '.' `elem` s
then dropDot s
else ""
where
dropDot s =
case elemIndex '.' s of
Just i -> dropDot (drop (i + 1) s)
Nothing -> s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.