fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100000;
  5.  
  6. int main() {
  7. int n, v[MAX_LENGTH + 1];
  8. cin >> n;
  9. int nuleCount = 0, firstPos = 1, lastPos = 0;
  10. for (int i = 1; i <= n; ++i) {
  11. cin >> v[i];
  12. }
  13.  
  14. int flag = 1;
  15. for (int i = 1; i < n; ++i) {
  16. int counter = 0;
  17. if (v[i] * v[i + 1] == 0) {
  18. ++nuleCount;
  19. } else if (v[i] * v[i + 1] != 0) {
  20. lastPos = i;
  21. firstPos = i - nuleCount;
  22. }
  23. }
  24. for (int i = firstPos; i <= lastPos; ++i) {
  25. cout << v[i] <<" ";
  26. }
  27. // cout << firstPos << " " << lastPos;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5316KB
stdin
9
1 2 3 4 0 1 0 5 6 
stdout
4 0 1 0 5