Skip to content

Instantly share code, notes, and snippets.

@jkramer
Created January 11, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkramer/12e31696794876ad6dd1 to your computer and use it in GitHub Desktop.
Save jkramer/12e31696794876ad6dd1 to your computer and use it in GitHub Desktop.
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