jfz-2023-s473579/TaskF00/run.py

33 lines
1014 B
Python
Raw Normal View History

2024-01-08 12:43:44 +01:00
import re
2024-01-08 13:06:56 +01:00
import sys
2024-01-08 12:43:44 +01:00
def replace_digits_with_letters(input_string):
digit_to_letter = {'0': 'a', '1': 'b', '2': 'c', '3': 'd', '4': 'e', '5': 'f', '6': 'g', '7': 'h', '8': 'i', '9': 'j'}
def replace(match):
number = match.group()
replaced_number = ''.join(digit_to_letter[digit] for digit in number)
return replaced_number
pattern = re.compile(r'\b\d{4}\b|\d{4}')
result = pattern.sub(replace, input_string)
return result
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(replace_digits_with_letters(row), output_file)
2024-01-08 13:06:56 +01:00
# output_file ='simple.out'
# input_file = 'simple.in'
input_file = sys.argv[1]
output_file = sys.argv[2]
2024-01-08 12:43:44 +01:00
main_function(input_file, output_file)