题解 | #长方形的关系#
长方形的关系
https://www.nowcoder.com/practice/6b099f3a8e3745b592203f14e3954411
#include<bits/stdc++.h>
#include<string>
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){
if((length>=a.length&&width>=a.width)||(length>=a.width&&width>=a.length)){/*
不管是长还是宽,都可以进行比较,只要有一个通过就能成立*/
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;
}
关于这道题,我还有一个思路,就是先比较两个长方性的长和宽,然后确定长和宽,再分别进行比较,如果有用这个方法做出来的伙伴,欢迎私聊我
查看7道真题和解析