CPP60. 长方形的关系
描述
给出两个长方形的长和宽(长不一定大于宽),实现长方形类的一个方法,判定前者是否能完全覆盖后者。输入描述
输入4个整数,前两个表示第一个长方形的长和宽,后两个表示第二个长方形的长和宽。输出描述
如果前者能完全覆盖后者输出"yes"否则输出"no"示例1
输入:
5 4 2 3
输出:
yes
C++ 解法, 执行用时: 2ms, 内存消耗: 476KB, 提交时间: 2022-04-21
#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 &b) { if((length>=b.getlength()&&width>=b.getwidth())||(length>=b.getwidth()&&width>=b.getlength())) 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; }
C++ 解法, 执行用时: 3ms, 内存消耗: 384KB, 提交时间: 2022-05-17
#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...... void cancover(rectangle a){ if(this->area()>=a.area()){ cout<<"yes"; } else{ cout<<"no"; } } }; int main(){ int l1,w1,l2,w2; cin>>l1>>w1>>l2>>w2; rectangle a,b; a.set(l1,w1); b.set(l2,w2); a.cancover(b); return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 388KB, 提交时间: 2022-05-21
#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 &r){ if((this->getlength()>=r.getlength()&&this->getwidth()>=r.getwidth())|| this->getlength()>=r.getwidth()&&this->getwidth()>=r.getlength()) 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; }
C++ 解法, 执行用时: 3ms, 内存消耗: 392KB, 提交时间: 2022-06-08
#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 b) { int l1 = max(length, width); int w1 = min(length, width); int l2 = max(b.length, b.width); int w2 = min(b.length, b.width); if (l1 >= l2 && w1 >= w2) 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; }
C++ 解法, 执行用时: 3ms, 内存消耗: 392KB, 提交时间: 2022-04-02
#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 b){ if(length>=(b.getlength()||width>=b.getwidth())&&length*width>=b.area()) 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; }