fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. class cool {
  5. public:
  6. int a, b;
  7. bool operator<(const cool& rhs) const
  8. {
  9. return a < rhs.a || a == rhs.a && b > rhs.b;
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. cool arr[5] = {{2, 1}, {2, 3}, {2, 2}, {3, 1}, {1, 1}};
  16. std::sort(arr, arr+5);
  17. for (int i = 0; i < 5; ++i)
  18. {
  19. std::cout << '(' << arr[i].a << ", " << arr[i].b << ") ";
  20. }
  21. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
(1, 1) (2, 3) (2, 2) (2, 1) (3, 1)