Skip to content
Snippets Groups Projects
16.py 1.46 KiB
Newer Older
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")