分别输入两个空间中两个矩形的左上角坐标x,y,以及宽(width)高(height), 如果两个矩形有相交,输出相交的矩形左上角,右下角坐标,x1,y1,x2,y2
例如: 键盘输入: 0,0,100,100 20,20,100,40 输出: 20,20,100,60
# include <iostream>
# include <utility>
using namespace std;
struct stRect{
int _x, _y;
int _width, _height;
};
int main(){
stRect rect1, rect2;
cout << "Rect1:\n";
cin >> rect1._x >> rect1._y >> rect1._width >> rect1._height;
cout << "Rect2:\n";
cin >> rect2._x >> rect2._y >> rect2._width >> rect2._height;
int x1,y1,x2,y2;
x1 = max(rect1._x, rect2._x);
y1 = max(rect1._y, rect2._y);
x2 = min(rect1._x+rect1._width,rect2._x+rect2._width);
y2 = min(rect1._y+rect1._height,rect2._y+rect2._height);
cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}
/*
Rect1:
0 0 100 100
Rect2:
20 20 100 40
20 20 100 60
请按任意键继续. . .
*/