fork download
  1. #include<iostream>
  2. #include<queue>
  3.  
  4. using namespace std;
  5. class LegoBrick{
  6. private:
  7. double width, height;
  8. string color;
  9. public:
  10. LegoBrick(double w, double h):width(w),height(h){
  11.  
  12. }
  13. void print() const{
  14. cout<<width<<" "<<height<<endl;
  15. }
  16. const double area(){
  17. return width*height;
  18. }
  19. };
  20. struct CMP{
  21. bool operator()(LegoBrick& a, LegoBrick& b){
  22. return a.area()<b.area();
  23. }
  24. };
  25. int main(){
  26. vector<LegoBrick> v= {LegoBrick{1,2},LegoBrick{2,4},LegoBrick{1,1},LegoBrick{4,2},LegoBrick{3,3},
  27. LegoBrick{1,5},LegoBrick{2,2},LegoBrick{2,5}
  28. };
  29. priority_queue<LegoBrick, vector<LegoBrick>, CMP> fav(v.begin(), v.end());
  30. for(int i=0; i<3; ++i){
  31. fav.top().print();
  32. fav.pop();
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5560KB
stdin
Standard input is empty
stdout
2 5
3 3
4 2