fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <cmath>
  4.  
  5. class C {
  6. private:
  7. double a, b;
  8. public:
  9. C() {}
  10. C(double a, double b) { this->a = a; this->b = b; }
  11. friend double myabs(C c) { return sqrt(c.a * c.a + c.b * c.b); }
  12. friend std::ostream &operator<<(std::ostream &s, C &c) {
  13. s << '(' << c.a << ',' << c.b << ')';
  14. return s;
  15. }
  16. };
  17.  
  18. class CCompare {
  19. public:
  20. bool operator()(C &r, C &s) { return myabs(r) < myabs(s); }
  21. };
  22.  
  23. int main() {
  24. C c;
  25. std::priority_queue<C, std::vector<C>, CCompare> pq;
  26. pq.push(C(3, 1));
  27. pq.push(C(4, 1));
  28. pq.push(C(5, 9));
  29. pq.push(C(2, 6));
  30. pq.push(C(5, 3));
  31. while (!pq.empty()) {
  32. c = pq.top();
  33. pq.pop();
  34. std::cout << c << std::endl;
  35. }
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 2876KB
stdin
Standard input is empty
stdout
(5,9)
(2,6)
(5,3)
(4,1)
(3,1)