22 lines
676 B
Python
22 lines
676 B
Python
|
string = input()
|
||
|
string_list = []
|
||
|
cursor = 0
|
||
|
for char in string:
|
||
|
# If 'L' found in string, we move the cursor to the left
|
||
|
if char == 'L':
|
||
|
if cursor > 0:
|
||
|
cursor -= 1
|
||
|
# If 'R' found in string, we move the cursor to the right
|
||
|
elif char == 'R':
|
||
|
if cursor < len(string):
|
||
|
cursor += 1
|
||
|
# If 'B' found in string, we delete the character to the left of the cursor
|
||
|
elif char == 'B':
|
||
|
del string_list[cursor - 1]
|
||
|
cursor -= 1
|
||
|
# If any other character found in string, we insert it to the left of the cursor
|
||
|
else:
|
||
|
string_list.insert(cursor, char)
|
||
|
cursor += 1
|
||
|
# Print only the new string, without the initial one
|
||
|
print(''.join(string_list))
|