fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. struct Point
  5. {
  6. int x;
  7. int y;
  8. };
  9.  
  10. int main()
  11. {
  12. Point ptLT{18, 4 };
  13. Point ptRT{28, 8 };
  14. Point ptRB{20, 40};
  15. Point ptLB{16, 6 };
  16.  
  17. Point ptMin;
  18. Point ptMax;
  19.  
  20. std::pair<int&, int&>(ptMin.x, ptMax.x) = std::minmax({ptLT.x, ptRT.x, ptRB.x, ptLB.x});
  21. std::pair<int&, int&>(ptMin.y, ptMax.y) = std::minmax({ptLT.y, ptRT.y, ptRB.y, ptLB.y});
  22.  
  23. std::cout << "pt min: (" << ptMin.x << ',' << ptMin.y << ")\n";
  24. std::cout << "pt max: (" << ptMax.x << ',' << ptMax.y << ")\n";
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4488KB
stdin
Standard input is empty
stdout
pt min: (16,4)
pt max: (28,40)