nq1s788

компаратор и сортировка

Aug 27th, 2025
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <deque>
  5. #include <map>
  6. #include <cmath>
  7. #include <random>
  8.  
  9. #define se second
  10. #define fi first
  11. #define mp make_pair
  12. #define pb push_back
  13.  
  14. typedef long long ll;
  15. typedef long double ld;
  16.  
  17. using namespace std;
  18.  
  19. bool cmp(int x, int y) {
  20.     if ((x % 2 == 1) && (y % 2 == 0)) return true;
  21.     if ((x % 2 == 0) && (y % 2 == 1)) return false;
  22.     return (x < y);
  23. }
  24.  
  25. int main(){
  26.     vector<int> a = {1, 4, 3, 5, 2, 6};
  27.     sort(a.begin(), a.end(), cmp);
  28.     for (auto e : a) cout << e << ' ';
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment