fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<deque>
  4. using namespace std;
  5.  
  6. struct myarr {
  7. deque<int> arr;
  8. bool flag = true;
  9. friend istream& operator >>(istream& in, myarr& marr) {
  10. in.ignore(2);
  11. for (int i{ 0 }; i < marr.arr.size(); i++) {
  12. in >> marr.arr[i];
  13. in.ignore();
  14. }
  15. return in;
  16. }
  17.  
  18. void popp() {
  19. if (flag) {
  20. arr.pop_front();
  21. }
  22. else {
  23. arr.pop_back();
  24. }
  25. }
  26.  
  27. void print_all() {
  28. if (flag) {
  29. cout << '[';
  30. while (arr.size() != 1) {
  31. cout << arr.front() << ',';
  32. arr.pop_front();
  33. }
  34. cout << arr.front();
  35. arr.pop_front();
  36. cout << ']';
  37. }
  38. else {
  39. cout << '[';
  40. while (arr.size() != 1) {
  41. cout << arr.back() << ',';
  42. arr.pop_back();
  43. }
  44. cout << arr.back();
  45. arr.pop_back();
  46. cout << ']';
  47. }
  48. }
  49. };
  50.  
  51. myarr d;
  52.  
  53.  
  54. int main() {
  55. int num;
  56. cin >> num;
  57. for (int j{ 0 }; j < num; j++) {
  58. d.flag = true;
  59. bool f = true;
  60. string s;
  61. cin >> s;
  62. int n;
  63. cin >> n;
  64. d.arr.resize(n);
  65. cin >> d;
  66. for (int i{ 0 }; i < s.length(); i++) {
  67. if (s[i] == 'R') {
  68. if (d.flag){
  69. d.flag = false;
  70. }
  71. else {
  72. d.flag = true;
  73. }
  74. }
  75. else {
  76. if (d.arr.size() == 0) {
  77. cout << "error";
  78. cout << '\n';
  79. f = false;
  80. break;
  81. }
  82. d.popp();
  83. }
  84. }
  85. if(f){
  86. if (d.arr.size() == 0) {
  87. cout << "[]" << '\n';
  88. }
  89. else {
  90. d.print_all();
  91. cout << "\n";
  92. }
  93. }
  94. }
  95. return 0;
  96. }
Success #stdin #stdout 0.01s 5520KB
stdin
2
D
0
[]
R
0
[]
stdout
error
error