首页 > 代码库 > UVA 12714 Two Points Revisited(简单数学题)

UVA 12714 Two Points Revisited(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4452


题意: 给出两个点组成一条直线,要你任意输出两个点,要求这两点组成的直线和给出的直线垂直(注意输出的点不能有负数);


代码如下:

#include <cstdio>
int main()
{
	int n, x1, x2, y1, y2;
	int cas = 0;
	while(~scanf("%d",&n))
	{
		while(n--)
		{
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			printf("Case %d: ",++cas);
			if(x1 == x2)
			{
				printf("0 0 1 0\n");
				continue;
			}
			if(y1 == y2)
			{
				printf("0 0 0 1\n");
				continue;
			}
			if(x1-x2>0 && y1-y2>0)
			{
				printf("%d 0 0 %d\n",y1-y2,x1-x2);
			}
			else if(x1-x2>0 && y1-y2<0)
			{
				printf("0 0 %d %d\n",y2-y1,x1-x2);
			}
			else if(x1-x2<0 && y1-y2>0)
			{
				printf("0 0 %d %d\n",y1-y2,x2-x1);
			}
			else if(x1-x2<0 && y1-y2<0)
			{
				printf("%d 0 0 %d\n",y2-y1,x2-x1);
			}
		}
	}
	return 0;
}