Newer
Older
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
from sys import stdin
search_task = input().lower().split()
filenames = [line.rstrip("\n") for line in stdin]
is_something = False
for fname in filenames:
active_searches = []
ind = 0
f = False
with open(fname, "r", encoding="utf-8") as file:
for line in file:
for word in line.replace(" ", " ").rstrip("\n").lower().split():
if not word:
continue
if word == search_task[0]:
active_searches.append([word])
continue
if active_searches:
for i in range(len(active_searches) - 1, -1, -1):
if len(active_searches[i]) == len(search_task):
f = True
break
elif search_task[len(active_searches[i])] == word:
active_searches[i].append(word)
else:
del active_searches[i]
if f:
break
if active_searches:
for i in range(len(active_searches) - 1, -1, -1):
if len(active_searches[i]) == len(search_task):
f = True
break
if f:
break
if f:
print(fname)
is_something = True
if not is_something:
print("404. Not Found")