题解 | #长方形的关系#
长方形的关系
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;
}
string cancover(rectangle r)
{
string str;
if (((*this).find_min() >= r.find_min()) && ((*this).find_max() >= r.find_max()))
str = "yes";
else
str = "no";
return str;
}
int find_min()
{
if ((*this).getlength() < (*this).getwidth())
return (*this).getlength();
else
return (*this).getwidth();
}
int find_max()
{
if ((*this).getlength() > (*this).getwidth())
return (*this).getlength();
else
return (*this).getwidth();
}
// write your code here......
};
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;
}
要注意的是长不一定等于宽,所以判断第一个长方形最长边是否大于第二个长方形的最长边,第一个长方形的最短边是否大于第二个长方形的最短边。
C++题解 文章被收录于专栏
记录在牛客网用C++刷题的题解思路
