-
Notifications
You must be signed in to change notification settings - Fork 0
/
[5430]AC.py
39 lines (33 loc) · 922 Bytes
/
[5430]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
from collections import deque
def delete(flipped, deq):
if flipped:
deq.pop()
else:
deq.popleft()
def func(numbers, p):
deq = deque()
for i in numbers:
deq.append(i)
flipped = False
for i in list(p):
if i == "D":
if deq:
delete(flipped, deq)
else:
return "error"
elif i == "R":
flipped = not flipped
elif i == "F":
flipped = not flipped
if deq:
delete(flipped, deq)
else:
return "error"
return str(list(deq)[::-1] if flipped else list(deq)).replace(" ", "")
for _ in range(int(input())):
p = input().replace("RR", "").replace("RD", "F")
n = int(input())
numbers = list(map(int, input().strip("[]").split(","))) if n else input()
if not n:
numbers = []
print(func(numbers, p))