Advertisement
Carbastan

Halfsort3

Nov 26th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #define N 100005
  4.  
  5. using namespace std;
  6.  
  7. ifstream cin("halfsort3.in");
  8. ofstream cout("halfsort3.out");
  9.  
  10. int v[N];
  11.  
  12. int main()
  13. {
  14.     int n;
  15.     cin >> n;
  16.  
  17.     for(int i = 1; i <= n; ++ i) cin >> v[i];
  18.  
  19.     for(int i = 1; i <= n - 1; ++ i)
  20.     {
  21.         for(int j = i + 1; j <= n; ++ j)
  22.         {
  23.             if((v[i] % 2 == 0 and v[j] % 2 == 0 and v[i] > v[j]) or (v[i] % 2 != 0 and v[j] % 2 != 0 and v[i] < v[j]))
  24.                 swap(v[i], v[j]);
  25.         }
  26.     }
  27.  
  28.     for(int i = 1; i <= n; ++ i) cout << v[i] << " ";
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement