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

5 10 20 30 40 50 7 1 60 2 1 70 2 1 80 2 1 90--6
 10 20 30 40 50 90  

5
 100000 200000 300000 400000 500000 
3 
2 
1 1000000 
1 2000000--6
 100000 200000 300000 400000 1000000 2000000 

4 
5 10 15 20 
4 
2 
1 -25 
2 --2 5 10
2
stdout
7
 1 2 3 0 0 0 0