题解 | #长方形的关系#
长方形的关系
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......
string cancover(rectangle &a)
{
string y = "yes";
string n = "no";
if(
getlength() >= a.length && getwidth() >= a.width
|| getlength() >= a.width && getwidth() >= a.length
)
return y;
else
return n;
}
};
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;
}
查看10道真题和解析