32 lines
726 B
Python
32 lines
726 B
Python
import sys
|
||
|
||
try:
|
||
sys.stdout.reconfigure(encoding="utf-8")
|
||
sys.stdin.reconfigure(encoding="utf-8")
|
||
except (AttributeError, ValueError):
|
||
pass
|
||
|
||
RLE = ""
|
||
ALM = ""
|
||
PUNCTUATION = "!?.,;:…"
|
||
|
||
|
||
def transform(message):
|
||
trailing = ""
|
||
while message and message[-1] in PUNCTUATION:
|
||
trailing = message[-1] + trailing
|
||
message = message[:-1]
|
||
if "|" in message:
|
||
head, _, tail = message.partition("|")
|
||
body = head + RLE + trailing + RLE + RLE + tail.replace("|", RLE)
|
||
else:
|
||
body = message + RLE + trailing + RLE + RLE
|
||
return body + ALM + ALM + RLE
|
||
|
||
|
||
while True:
|
||
try:
|
||
print(transform(input("> ")))
|
||
except (KeyboardInterrupt, EOFError):
|
||
break
|