-
Notifications
You must be signed in to change notification settings - Fork 14
/
11988-BrokenKeyboard.py
37 lines (35 loc) · 991 Bytes
/
11988-BrokenKeyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
from collections import deque
import re, array
input = lambda:sys.stdin.readline()
import functools
@functools.lru_cache(maxsize = 1000000)
def Main():
while True:
try:
line = input().strip()
except EOFError:
break
result = deque()
currBuffer = []
tail = True
for c in line:
if c == '[':
if tail == True:
result.append(''.join(currBuffer))
currBuffer = []
tail = False
elif c == ']':
if tail == False:
result.appendleft(''.join(currBuffer))
currBuffer = []
tail = True
else:
currBuffer.append(c)
if tail:
result.append(''.join(currBuffer))
else:
result.appendleft(''.join(currBuffer))
print (''.join(result))
if __name__ == '__main__':
Main()