fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stack>
  4. #include <queue>
  5. using namespace std;
  6. stack<int> parsing(const string& s) {
  7. stack<int> ret;
  8. for (int i = 1; i < s.size() - 1; i++) {
  9. int cur = 0;
  10. while (isdigit(s[i])) {
  11. cur = 10 * cur + s[i] - '0';
  12. i++;
  13. }
  14. ret.push(cur);
  15. }
  16. return ret;
  17. }
  18.  
  19. int main(int argc, char const *argv[])
  20. {
  21. int n;
  22.  
  23. scanf("%d",&n);
  24. for(int i = 0; i<n; i++){
  25. queue<int> arr;
  26.  
  27. char c[100001];
  28. string integer;
  29. scanf("%s",c);
  30. int m = 0;
  31. scanf("%d",&m);
  32. int countj = 0;
  33. cin >> integer;
  34. stack<int> stk = parsing(integer);
  35. int ccc = stk.size();
  36. for(int k = 0; k<ccc; k++){
  37. arr.push(stk.top()); stk.pop();
  38. }
  39. for(int k = 0; k<ccc; k++){
  40. stk.push(arr.front());
  41. arr.pop();
  42. }
  43.  
  44.  
  45. int error = 0;
  46. int count = 0;
  47. while(c[count] != '\0'){
  48. if(c[count] == 'R'){
  49. ccc = stk.size();
  50. for(int j = 0; j<ccc; j++){
  51. arr.push(stk.top()); stk.pop();
  52. }
  53. for(int j = 0; j<ccc; j++){
  54. stk.push(arr.front());
  55. arr.pop();
  56. }
  57. }
  58. if(c[count] == 'D'){
  59. if(stk.empty() == 1){
  60. error = 1;
  61. break;
  62. }
  63. else{
  64. stk.pop();
  65. }
  66. }
  67. count++;
  68. }
  69. if(error){
  70. printf("error\n");
  71. }
  72. else{
  73. count = stk.size();
  74. printf("[");
  75. for(int j = 0; j<count-1; j++){
  76. printf("%d,",stk.top());stk.pop();
  77. }
  78. printf("%d",stk.top());stk.pop();
  79. printf("]\n");
  80. }
  81. }
  82. return 0;
  83. }
  84.  
  85.  
Runtime error #stdin #stdout 0.04s 5268KB
stdin
1
R
0
[]
stdout
Standard output is empty