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;
  8. cin >> n;
  9. for (int i = 0; i < n; ++i) {
  10. cin >> v[i];
  11. }
  12. int size = n;
  13. cin >> m;
  14. while (m--) {
  15. cin >> k;
  16. if (k == 1) {
  17. cin >> x;
  18. if (size < MAX_SIZE) {
  19. v[size] = x;
  20. ++size;
  21. }
  22. } else if (k == 2) {
  23. if (size > 0) {
  24. --size;
  25. }
  26. }
  27. }
  28. cout << size << "\n";
  29. for (int i = 0; i < size; ++i) {
  30. cout << v[i] << " ";
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 5284KB
stdin
3
1 2 3 
3
2
2
2
-0

7
5 -4 0 -7 7 7 2
5
2
1 100
2
1 0
1 3
-8
5 -4 0 -7 7 7 0 3

3
1 2 3 
6
1 9
1 9
1 9
1 9
1 9
1 9
-9
1 2 3 9 9 9 9 9 9

https://l...content-available-to-author-only...e.ro/submission/1592550
stdout
0