-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBACKJOON5430.py
More file actions
41 lines (34 loc) · 883 Bytes
/
BACKJOON5430.py
File metadata and controls
41 lines (34 loc) · 883 Bytes
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
38
39
40
41
# AC
import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
result = []
for _ in range(t):
cmd = input().strip()
size = int(input())
array = input().strip()
if size == 0 :
num = deque()
else :
num = deque(map(int, array[1:-1].split(',')))
reverseFlag = False
errorFlag = False
for c in cmd:
if c == "R":
reverseFlag = not reverseFlag
elif c == "D":
if len(num) == 0 :
result.append("error")
errorFlag = True
break
else :
if reverseFlag :
num.pop()
else :
num.popleft()
if not errorFlag :
if reverseFlag :
num.reverse()
result.append("[" + ",".join(map(str, num)) + "]")
print("\n".join(result))