-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path(5430)AC.py
More file actions
36 lines (34 loc) · 804 Bytes
/
(5430)AC.py
File metadata and controls
36 lines (34 loc) · 804 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
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
for i in range(n):
a = input().strip()
m = int(input())
flag = 1
arr = input().strip()
dq = deque(arr[1:-1].split(','))
if m == 0:
dq = deque()
R = 0
for i in range(len(a)):
if a[i] == 'R':
R += 1
elif a[i] == 'D':
if len(dq) == 0:
print('error')
flag = 0
break
else:
if R % 2 == 0:
dq.popleft()
else:
dq.pop()
if flag == 0:
continue
else:
if R % 2 == 0:
print('[' + ",".join(dq) + ']')
else:
dq.reverse()
print('[' + ",".join(dq) + ']')