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



10 6
0 1 2 3 4 5 6 7 8 9
1
1
2 22
2 33
1
1-8
4 5 6 7 8 9 22 33 

2 9
1 2
2 0
2 1
2 2
2 3
2 4
2 5
2 6
2 7 
2 8- 10
1 0 1 2 3 4 5 6 7 8 


10 4
0 1 2 3 4 5 6 7 8 9
1
1
2 22
2 33-10
2 3 4 5 6 7 8 9 22 33

10 10
0 1 2 3 4 5 6 7 8 9
1
1
1
1
1
1
1
1
1
1-0


1 3
20
2 11
2 22
2 33 -4
20 11 22 33


4 3
30 21 81 26
2 68
2 64
1 -5
21 81 26 68 64
stdout
2
55 66