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