Created
June 3, 2015 07:15
-
-
Save ZengetsuFR/18d7de41053e04e3a33c to your computer and use it in GitHub Desktop.
Résolution du jeu "MIME Type" sur le site codingame.com
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 sys, math,re | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
N = int(raw_input()) # Number of elements which make up the association table. | |
Q = int(raw_input()) # Number Q of file names to be analyzed. | |
d ={} | |
#dico avec extension en cle et le type mime pour valeur | |
for i in xrange(N): | |
EXT, MT = raw_input().split() | |
if len(EXT)<=10 and len(MT)<=50: | |
d[EXT.lower()]=MT | |
for l in xrange(Q): | |
FNAME = raw_input() # One file name per line. | |
#Expression reguliere pour verifier qu'il | |
m = re.search(r"\.[0-9A-Za-z]{1,10}$",FNAME.lower()) | |
v = "UNKNOWN" | |
if m != None: | |
try: | |
#on utilise m comme cle pour le dico d | |
#doit retourner le type mime si la cle existe | |
v = d[FNAME.lower()[m.start()+1:]] | |
except: | |
v="UNKNOWN" | |
print v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment