29 lines
949 B
Python
29 lines
949 B
Python
import re, sys
|
|
|
|
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:]
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
for line in sys.stdin:
|
|
line = line.rstrip("\n")
|
|
line = zad_01(line)
|
|
print(line) |