Created
January 11, 2016 14:02
-
-
Save jkramer/12e31696794876ad6dd1 to your computer and use it in GitHub Desktop.
CodinGame - MIME Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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