djfz-2023-s464933/TaskF01/run.py

29 lines
949 B
Python
Raw Permalink Normal View History

2024-01-29 23:18:03 +01:00
import re, sys
2024-01-07 21:21:03 +01:00
2024-01-29 23:18:03 +01:00
def change_chars_in_string(string:str, new_chars:str, index:int) -> str:
new_chars_size = len(new_chars)
return string[:index] + new_chars + string[index+new_chars_size:]
2024-01-07 21:21:03 +01:00
2024-01-29 23:18:03 +01:00
def zad_01(line:str) -> str:
uppercase_pattern = "[A-ZĄĆĘŁŃÓŚŹŻ]"
lowercase_pattern = "[a-ząćęłńóśźż]"
matches = re.finditer('\w+',line)
for match in matches:
match_word = match.group()
if re.search(uppercase_pattern,match_word) and re.search(lowercase_pattern,match_word):
new_word = ""
for m in match_word:
if re.search(uppercase_pattern,m):
new_word += m.lower()
elif re.search(lowercase_pattern,m):
new_word += m.upper()
line = change_chars_in_string(line,new_word,match.start())
return line
2024-01-07 21:21:03 +01:00
2024-01-29 23:18:03 +01:00
for line in sys.stdin:
line = line.rstrip("\n")
line = zad_01(line)
print(line)