-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC.py
47 lines (35 loc) · 828 Bytes
/
AC.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
38
39
40
41
42
43
44
45
from collections import deque
n = int(input())
for _ in range(n):
com = input()
k = int(input())
arr = input()
arr = arr[1:-1]
if arr:
arr = list(arr.split(","))
dq = deque(arr)
if k == 0:
dq = deque()
flag = 1
R = 0
for j in range(len(com)):
if com[j] == 'R':
R +=1
elif com[j] == 'D':
if dq:
if R % 2 == 0:
dq.popleft()
else:
dq.pop()
else:
print("error")
flag = 0
break
if flag == 0:
continue
else:
if R % 2 == 0:
print('[' + ",".join(dq) + ']')
else:
dq.reverse()
print('[' + ",".join(dq) + ']')