29 lines
838 B
Python
29 lines
838 B
Python
import re2
|
|
|
|
def build_surname_regex(surnames):
|
|
# Create a regular expression pattern from the list of surnames
|
|
pattern = r'\b(?:' + '|'.join(surnames) + r')\b'
|
|
return re2.compile(pattern)
|
|
|
|
def main():
|
|
# Load Polish surnames from the file
|
|
with open('polish_surnames.txt', 'r', encoding='utf-8') as file:
|
|
polish_surnames = [line.strip().lower() for line in file]
|
|
|
|
# Build a DFA regex pattern from the list of surnames
|
|
surname_regex = build_surname_regex(polish_surnames)
|
|
|
|
while True:
|
|
try:
|
|
# Read a line from standard input
|
|
line = input()
|
|
|
|
# Check if the line contains any of the Polish surnames
|
|
if surname_regex.search(line.lower()):
|
|
print(line)
|
|
except EOFError:
|
|
break
|
|
|
|
if __name__ == "__main__":
|
|
main()
|