djfz-2023-s464933/TaskF05/run.py

30 lines
687 B
Python
Raw Normal View History

2024-01-07 21:21:03 +01:00
import re
import sys
def replaceThirdWordWithX(input):
2024-01-14 17:25:11 +01:00
empty0 = input.group(1)
group1 = input.group(2)
empty1 = input.group(3)
group2 = input.group(4)
empty2 = input.group(5)
group3 = "x" * (len(input.group(6)))
rest = input.group(7)
if empty0 is None:
return f'{group1}{empty1}{group2}{empty2}{group3}{rest}'
else:
return f'{empty0}{group1}{empty1}{group2}{empty2}{group3}{rest}'
2024-01-07 21:21:03 +01:00
2024-01-14 17:25:11 +01:00
pattern = r'(\W+)?(\w+)(\W+)(\w+)(\W+)(\w+)(.*)'
2024-01-07 21:21:03 +01:00
for line in sys.stdin:
line = line.strip('\n')
match = re.match(pattern, line)
if match:
result = replaceThirdWordWithX(match)
2024-01-14 17:25:11 +01:00
print(result)
2024-01-07 21:21:03 +01:00
else:
print(line)