fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int s;
  6. deque<int> dq;
  7.  
  8. int main() {
  9. cin >> s;
  10. int counter = 1;
  11. while(s--) {
  12. char c; cin >> c;
  13. char x; cin >> x;
  14. if(c == 'A') {
  15. counter++;
  16. if(x == 'L') dq.push_front(counter);
  17. else dq.push_back(counter);
  18. } else {
  19. int k; cin >> k;
  20. for(int i = 1; i <= k; i++) {
  21. if(x == 'L') dq.pop_front();
  22. else dq.pop_back();
  23. }
  24. }
  25. }
  26. while(!dq.empty()) {
  27. cout << dq.front() << "\n";
  28. dq.pop_front();
  29. }
  30. }
Success #stdin #stdout 0.01s 5264KB
stdin
7
A L
A R
A L 
A R
D R 2
A R
D L 1
stdout
2
6