题解 | #长方形的关系#

长方形的关系

https://www.nowcoder.com/practice/6b099f3a8e3745b592203f14e3954411

#include<bits/stdc++.h>
using namespace std;
class rectangle {
  private:
    int length, width;
  public:
    void set(int x, int y) {
        length = x;
        width = y;
    }
    int getlength() {
        return length;
    }
    int getwidth() {
        return width;
    }
    int area() {
        return length * width;
    }
    // write your code here......
    int findMax() {
        if (length > width) {
            return length;
        } else {
            return width;
        }
    }
    int findMin() {
        if (length < width) {
            return length;
        } else {
            return width;
        }
    }
    string cancover(rectangle& rec) {
        if (this->area() < rec.area()) {
            return "no";
        } else if (this->findMax() >= rec.findMax() &&
                   this->findMin() >= rec.findMin()) {
            return "yes";
        } else {
            return "no";
        }
    }
};
int main() {
    int l1, w1, l2, w2;
    cin >> l1 >> w1 >> l2 >> w2;
    rectangle a, b;
    a.set(l1, w1);
    b.set(l2, w2);
    cout << a.cancover(b);
    return 0;
}

全部评论

相关推荐

牛客66512506...:那个百度acg是不是个小哥啊,老是问些底层问题狠狠为难,然后kpi
哪些公司在招寒假实习?
点赞 评论 收藏
分享
2025-12-19 21:53
门头沟学院 Java
想做OpenGL:不要一来就把自己定位这么低吧,把大厂当成目标,不断去学技术做项目,最后你至少能学到能找到中小厂的技术水平,你一上来就找这种两千块还要前后端都会的,其实对你用处不会很大,真去了也是打杂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务