fork download
  1. T = int(input())
  2.  
  3. for t in range(1, T+1):
  4. p = input()
  5. n = int(input())
  6. x = input()[1:-1]
  7. if len(x) > 0:
  8. x = list(map(int, x.split(',')))
  9. cnt = 0
  10. ans = True
  11. r_cut, l_cut = 0, 0
  12.  
  13. for i in p:
  14. if i == 'R' and len(x) > 0:
  15. cnt += 1
  16. r_cut, l_cut = l_cut, r_cut
  17. elif i == 'D':
  18. if r_cut + l_cut == len(x):
  19. ans = False
  20. break
  21. else:
  22. l_cut += 1
  23.  
  24. if ans:
  25. if cnt % 2 == 1:
  26. x.reverse()
  27.  
  28. x = x[l_cut:len(x)-r_cut]
  29.  
  30. x = str(x)[1:-1]
  31. x = x.replace(', ', '')
  32. print("[" + ",".join(x) + "]")
  33. else:
  34. print('error')
Success #stdin #stdout 0.05s 9828KB
stdin
1
R
1
[12]
stdout
[1,2]