-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5015.py
74 lines (69 loc) · 1.96 KB
/
P5015.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# https://www.acmicpc.net/problem/5015
# 2020-07-09 / 5015. ls / Gold III
# ################## 틀렸습니다
# import sys
# P = sys.stdin.readline().rstrip()
# N = int(input())
# for i in range(N):
# F = sys.stdin.readline().rstrip()
# # 왼쪽끝과 오른쪽끝이 와카가 아닐때 일치하는지 여부
# non_wc = P.split("*")
# min_idx = 0
# for w in non_wc[:-1]:
# idx = F.find(w, min_idx)
# if idx == -1:
# break
# # print(idx)
# min_idx = idx + len(w)
# else:
# # 마지막이 일치하지 않는 경우
# if non_wc[-1] and non_wc[-1] != F[-len(non_wc[-1]):]:
# continue
# print(F)
# ################## 시간 초과. 재귀 써서 그런가봄
# import sys
# import re
# def search(L: list, pos: int, prev: int, length: int):
# if pos == len(L):
# return prev == length
# for st, ed in L[pos]:
# if prev <= st:
# res = search(L, pos + 1, ed, length)
# if res:
# return True
# else:
# pass
# # print(f"{pos}: {res}")
# return False
# P = sys.stdin.readline().rstrip()
# P = re.sub("[*]+", "*", P)
# non_wc = P.split("*")
# # non_wc_orig = P.split("*")
# # non_wc = [n for n in non_wc_orig]
# # non_wc_len = [len(n) for n in P]
# N = int(input())
# for i in range(N):
# F: str = sys.stdin.readline().rstrip()
# pos_list = []
# for w in non_wc:
# idx = 0
# pos = []
# while True:
# x = F.find(w, idx)
# if x == -1:
# break
# pos.append((x, x + len(w)))
# idx = x + len(w) if w else x + 1
# pos_list.append(pos)
# # print(pos_list)
# if search(pos_list, 0, 0, len(F)):
# print(F)
##############
import sys
import re
P = sys.stdin.readline().rstrip()
P = re.sub("[*]+", "*", P)
non_wc = P.split("*")
N = int(input())
for i in range(N):
F = sys.stdin.readline().rstrip()