fork download
  1. import sys
  2.  
  3. t = int(sys.stdin.readline().rstrip())
  4.  
  5. for i in range(t):
  6. p = sys.stdin.readline().rstrip()
  7. n = int(sys.stdin.readline().rstrip())
  8. arr = sys.stdin.readline().rstrip()
  9.  
  10. revCount = False
  11.  
  12. try:
  13. arr = arr[1:-1]
  14.  
  15. if len(arr) > 0:
  16. arr = list(map(int, arr.split(',')))
  17. else:
  18. arr = []
  19.  
  20.  
  21. for i in p:
  22. if i == 'R':
  23. if revCount == False:
  24. revCount = True
  25.  
  26. elif revCount == True:
  27. revCount = False
  28.  
  29. if i == 'D':
  30. if revCount == False:
  31. del arr[0]
  32. elif revCount == True:
  33. arr.pop()
  34.  
  35.  
  36. if revCount == True:
  37. arr.sort(reverse=True)
  38. print('[', end='')
  39. print(*arr, sep=',', end='')
  40. print(']')
  41. else:
  42. print('[', end='')
  43. print(*arr, sep=',', end='')
  44. print(']')
  45. except:
  46. print("error")
Success #stdin #stdout 0.03s 9712KB
stdin
1
R
2
[2,1]
stdout
[2,1]