fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n; cin >> n;
  7. deque<int> qu;
  8. for(int i = 1; i <= n; ++ i){
  9. int x; cin >> x;
  10. qu.push_back(x);
  11. }
  12. bool check;
  13. while(!qu.empty() && check){
  14. int m = qu.size() - 1;
  15. check = false;
  16. while(m > 0){
  17. int x = qu.front();
  18. qu.pop_front();
  19. if(qu.empty()){
  20. qu.push_back(x);
  21. break;
  22. }
  23. if(x + qu.front() & 1) qu.push_back(x);
  24. else{
  25. qu.pop_front();
  26. -- m;
  27. check = true;
  28. }
  29. -- m;
  30. }
  31. int x = qu.front(); qu.pop_front(); qu.push_back(x);
  32. for(int i = 0; i < qu.size(); ++ i) cout << qu[i] << " ";
  33. cout << '\n';
  34. }
  35.  
  36. cout << qu.size();
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5288KB
stdin
7
1 2 2 3 2 5 6
stdout
7