Advertisement
nq1s788

компаратор по убыванию второго элемента в паре

Jan 25th, 2025
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "Animal.cpp"
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. bool cmp(pair<int, int> x, pair<int, int> y) {
  10.     return x.second > y.second;
  11. }
  12.  
  13. int main() {
  14.     vector<pair<int, int>> a = {{1, 3}, {2, 8}, {1, 4}, {-2, 5}, {8, -6}};
  15.     sort(a.begin(), a.end(), cmp);
  16.     for (auto e : a) {
  17.         cout << e.first << ' ' << e.second << '\n';
  18.     }
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement