-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime_type.py
43 lines (36 loc) · 1.28 KB
/
mime_type.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import math
# MIME Type
# https://www.codingame.com/ide/puzzle/mime-type
n = int(input()) # Number of elements which make up the association table.
q = int(input()) # Number Q of file names to be analyzed.
items = {}
for i in range(n):
# ext: file extension
# mt: MIME type.
ext, mt = input().split()
items[ext.lower()] = mt
print(items, file=sys.stderr)
for i in range(q):
fname = input() # One file name per line.
ext = fname.split('.')
ext = list(filter(None, ext))
if len(ext) != 0:
ext = ext[-1]
else:
ext = ''
print("fname ", fname, "ext ", ext, file=sys.stderr)
print("ext ", ext, file=sys.stderr)
if ext.lower() in items:
if fname[-1] == '.' or fname is ext:
#print("fname: |",fname,"| ext: ", ext, ' UNKNOWN')
print('UNKNOWN')
#print("====================================================")
else:
#print("fname: |",fname,"| ext: ", ext, ' item: ', items[ext.lower()])
print(items[ext.lower()])
#print("====================================================")
else:
#print("fname: |",fname,"| ext: ", ext, ' UNKNOWN')
print('UNKNOWN')
#print("====================================================")