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