C language devil's square

Title Description

Legend in the distant past, there is a big devil entrenched in ACM / ICPC lab.

Big devil is very powerful, and he's had four law enforcement B, CD and want to see the big devil, the Warriors must defeat eleven B, CD the four law enforcement.

That day, the Warriors led his new team-mates again attacked the laboratory. They were greeted, first A law enforcement.

A recent law enforcement addicted square, determined to laboratories all rectangles are cut square. He tells warrior, laboratory with T rectangles, each rectangle sides parallel to the X-axis or Y-axis of the coordinate system. A law enforcement gives the coordinates of each vertex of a rectangle on a diagonal A, B, and A coordinate remains unchanged warrior, the largest rectangle into a square rectangle smaller than the original, and draw new square A, B1, C1, D1 four-point coordinates (clockwise), that even if the Warriors win.

Dear Warriors, won the Custodian, on closer away from the big devil it!

Entry

The first row contains a number T (T <= 100), indicates the number of test data sets.

Next T rows, each row comprising four integers x1, y1, x2, y2 (-100000 <= x1, y1, x2, y2 <= 100000), represent the coordinates of A, B two points.

Export

Each input corresponds to the output line 8 integers, denotes a square A, B1, C1, D1 coordinates of four points (clockwise).

Sample input Copy

2
0 0 2 3
3 2 -1 -1

Sample output Copy

0 0 0 2 2 2 2 0
3 2 3 -1 0 -1 0 2

Code

#include<stdio.h>
#include<math.h>
int main()
{
	int n,x1,x2,y1,y2,c,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		c=fabs(x1-x2);
		if(fabs(y1-y2)<c)c=fabs(y1-y2);
		if(x1>x2&&y1>y2)printf("%d %d %d %d %d %d %d %d\n",x1,y1,x1,y1-c,x1-c,y1-c,x1-c,y1);
		if(x1<x2&&y1<y2)printf("%d %d %d %d %d %d %d %d\n",x1,y1,x1,y1+c,x1+c,y1+c,x1+c,y1);
		if(x1>x2&&y1<y2)printf("%d %d %d %d %d %d %d %d\n",x1,y1,x1-c,y1,x1-c,y1+c,x1,y1+c);
		if(x1<x2&&y1>y2)printf("%d %d %d %d %d %d %d %d\n",x1,y1,x1+c,y1,x1+c,y1-c,x1,y1-c);
	}
	return 0;
}
Published 47 original articles · won praise 29 · views 1476

Guess you like

Origin blog.csdn.net/Qianzshuo/article/details/103759158