fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. bool f(int a, int b) {return (a%2 == 0 && b%2 == 0 && a > b) ||
  7. (abs(a%2) == 1 && abs(b%2) == 1 && a < b) ||
  8. (abs(a%2) > abs(b%2));}
  9.  
  10. int main() {
  11. int n;
  12. cin >> n;
  13. int a[n];
  14. for (int i = 0; i < n; i++)
  15. {
  16. cin >> a[i];
  17. }
  18. sort(a, a + sizeof(a) / sizeof(a[0]), f);
  19. for (auto e: a) cout << e << ' ';
  20. cout << endl;
  21. }
  22. // -5 3 7 9 4 2 -6
Success #stdin #stdout 0.01s 5536KB
stdin
7
9 2 3 -6 -5 4 7
stdout
-5 3 7 9 4 2 -6