code.cpp 859 B

123456789101112131415161718
  1. /* Write the function that takes three dimensions of a
  2. * brick: height(a), width(b) and depth(c) and returns true
  3. * if this brick can fit into a hole with the width(w) and height(h).
  4. * You can turn the brick with any side towards the hole.
  5. * We assume that the brick fits if its sizes equal the ones of the hole
  6. * (i.e. brick size should be less than or equal to the size of the hole,
  7. * not strickly less).
  8. */
  9. // (a,b,c) -- dimensions of the brick
  10. // (w,h) -- dimensions of the hole
  11. bool doesBrickFit(int a, int b, int c, int w, int h) {
  12. // put a,b,c into vector so sort can be used
  13. std::vector <int> abc = {a,b,c};
  14. // put lowest two values of a,b,c into a,b
  15. std::sort (abc.begin(),abc.end());
  16. // brick size should be less than or equal to the size of the hole
  17. return (w >= abc[0] && h >= abc[1]) || (w >= abc[1] && h >= abc[0]);
  18. }