-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path18_03_3.py
37 lines (31 loc) · 865 Bytes
/
18_03_3.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
import re
n, m = input().split(' ')
n = int(n)
m = int(m)
pat = re.compile(r'<int>|<str>|<path>')
pts = []
for i in range(n):
pt, name = input().split(' ')
int_mark = []
for j, pa in enumerate(pat.findall(pt)):
if pa == '<int>':
int_mark.append(j)
pt = pt.replace('<int>', '([0-9]+)')
pt = pt.replace('<str>', '([^/]+)')
pt = pt.replace('<path>', '(.+)')
pt = '^' + pt + '$'
pts.append((re.compile(pt), name, int_mark))
for i in range(m):
matched = False
url = input()
for pt, name, int_mark in pts:
res = pt.match(url)
if res != None:
res = list(res.groups())
for j in int_mark:
res[j] = str(int(res[j]))
print(' '.join([name] + res))
matched = True
break
if matched == False:
print('404')