zoj2099------------------------Frame Polygonal Line


You are going to read a sequence of pairs of integer numbers. Each pair represents the Cartesian coordinates of a point in a 2-dimentional plane. The first number is the x coordinate, while the second is that of y. The sequence represents a polygonal line. Your task is to draw a rectangle with minimal length of sides that exactly surrounds the polygonal line. The sides of the rectangle are parallel to x- and y-axis, respectively.


Input

Input consists of several test cases. For each case, a sequence of coordinates is given. Each pair of x and y occupies a line, with |x| and |y| less than 2^31. The sequence is terminated with a pair of 0's. Note that (0, 0) will never be considered as a point on any of the polygonal lines. An empty polygonal line signals the end of input.


Output

For each test case, print in one line two pairs of numbers, which are the south-west and north-east corners of the surrounding rectangle. The numbers must be separated by one space as is indicated in the samples.


Sample Input

12 56
23 56
13 10
0 0
12 34
0 0
0 0


Sample Output

12 10 23 56
12 34 12 34



输出最小最大横纵坐标即可


判断条件写错WA了很多次啊我去

因为x,y可能为负值所以不能用 x+y 判断两个都是零的情况,要用  x||y 啊啊啊啊!


代码:


#include <iostream>
using namespace std;

int main()
{
	int x,y;
	while(cin>>x>>y&&(x||y))
	{
		int max1=x;
		int max2=y;
		int min1=x;
		int min2=y;
		while(cin>>x>>y&&(x||y))
		{
			if(x>max1)
				max1=x;
			if(y>max2)
				max2=y;
			if(x<min1)
				min1=x;
			if(y<min2)
				min2=y;	
		}
		cout<<min1<<" "<<min2<<" "<<max1<<" "<<max2<<endl;
	}
	return 0;	
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值