fork download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <deque>
  4. #include <string.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int T, n;
  10. char p[1000001];
  11. char num[1000000];
  12. int flag;
  13. deque<int> d;
  14. int D(bool R) {
  15. if (d.empty()) {
  16. return 0;
  17. }
  18. if (R) {
  19. d.pop_front();
  20. }
  21. else {
  22. d.pop_back();
  23. }
  24. return 1;
  25. }
  26.  
  27. int main() {
  28. bool R = true;
  29. string str = "";
  30. int j = 0;
  31. scanf("%d", &T);
  32.  
  33. for (int i = 0; i < T; i++) {
  34. R = true;
  35. str = "";
  36. flag = 0;
  37. j = 0;
  38. scanf("%s", p);
  39. scanf("%d", &n);
  40. scanf("%s", num);
  41. while (n) {
  42. if (num[j] >= 49 && num[j] <= 57) {
  43. str += num[j];
  44. if (num[j + 1] == ',' || num[j+1]==']') {
  45. n--;
  46. d.push_back(atoi(str.c_str()));
  47. str = "";
  48. }
  49.  
  50. }
  51. j++;
  52. }
  53. for (int i = 0; i < strlen(p); i++) {
  54. if (p[i] == 'R') {
  55. R = !R;
  56. }
  57. else if (p[i] == 'D') {
  58. if (!D(R)) {
  59. flag = 1;
  60. printf("error\n");
  61. break;
  62. }
  63. }
  64. }
  65. if (!flag) {
  66. printf("[");
  67. while (!d.empty()) {
  68. if (R) {
  69. if (d.size() == 1) {
  70. printf("%d]\n", d.front());
  71. d.pop_front();
  72. }
  73. else {
  74. printf("%d,", d.front());
  75. d.pop_front();
  76. }
  77. }
  78. else {
  79. if (d.size() == 1) {
  80. printf("%d]\n", d.back());
  81. d.pop_back();
  82. }
  83. else {
  84. printf("%d,", d.back());
  85. d.pop_back();
  86. }
  87. }
  88. }
  89. }
  90. }
  91. return 0;
  92. }
Runtime error #stdin #stdout 0s 4560KB
stdin
1
R
1
[10]
stdout
Standard output is empty