jfz-2023-s473579/TaskF05/run.py
2024-01-20 23:38:38 +01:00

33 lines
871 B
Python

import re
import sys
def analyze_line(line):
word_pattern = r'\w+'
pattern = re.compile(r'(\w+ \w+ )(\w+)(.*)')
words = re.findall(word_pattern, line)
if len(words) >= 3:
modified_line = re.sub(pattern, r'\1' + 'x' * len(words[2]) + r'\3', line, count=1)
return modified_line
else:
return line
def write_answer(row, ouput_file):
with open(ouput_file, "a", encoding="utf-8") as file:
file.write(row)
def main_function(input_file, output_file):
with open(output_file, "w", encoding="utf-8") as output_file1:
with open(input_file, "r", encoding="utf-8") as file:
for row in file:
write_answer(analyze_line(row), output_file)
output_file ='simple.out'
input_file = 'simple.in'
# input_file = sys.argv[1]
# output_file = sys.argv[2]
main_function(input_file, output_file)