fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 10000;
  5.  
  6. int main() {
  7. int n, m, v[MAX_SIZE], k, x, t;
  8. cin >> n;
  9. t = n;
  10. for (int i = 1; i <= t; ++i) {
  11. cin >> v[i];
  12. }
  13. cin >> m;
  14. while(m--) {
  15. cin >> k;
  16. if(k == 1) {
  17. cin >> x;
  18. ++t;
  19. v[t] = x;
  20. } else {
  21. --t;
  22. }
  23. }
  24. if (t>0){
  25. cout << t << "\n ";
  26. for (int i = 1; i <= t; ++i) {
  27. cout << v[i] <<" ";
  28. }
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5272KB
stdin
3
1 2 3
3 
1 9
1 6 
1 0
stdout
6
 1 2 3 9 6 0