-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefdict.py
60 lines (48 loc) · 1.27 KB
/
defdict.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
'''
Input:
* n: int, m: int
* n=# of words group A (not necessarily unique)
* m=# of words group B
Goal:
* For each word in m, check if it's in A or not
* Yes: print index (1-based) of each occurrence space separated, -1 if none
'''
from collections import defaultdict
import sys
def main():
groupa_count = defaultdict(int)
groupa: List[str] = []
groupb: List[str] = []
key: str
n: int
m: int
n, m = [int(e) for e in input().split()]
for _ in range(n):
key = input()
groupa_count[key] += 1
groupa.append(key)
for _ in range(m):
groupb.append(input())
for item in groupb:
if item in groupa_count:
count = groupa_count[item]
offset = 0
indexes = []
while count:
index = groupa.index(item, offset)
offset = index + 1
# Add 1 to do 1-based indexing:
indexes.append(index + 1)
count -= 1
else:
indexes = [-1]
print(f'{" ".join(str(e) for e in indexes)}')
if __name__ == '__main__':
fd_open = False
if len(sys.argv) == 2:
fd = open(sys.argv[1])
sys.stdin = fd
fd_open = True
main()
if fd_open:
fd.close()