Chessboard Distance
Hazrat Ali
The Chessboard Distance for any two points (X1,Y1)(X1,Y1) and (X2,Y2)(X2,Y2) on a Cartesian plane is defined as max(∣X1−X2∣,∣Y1−Y2∣).
You are given two points (X1,Y1)(X1,Y1) and (X2,Y2)(X2,Y2). Output their Chessboard Distance.
Note that, ∣P∣∣P∣ denotes the absolute value of integer PP. For example, ∣−4∣=4 and ∣7∣=7.
Input Format
- First line will contain TT, the number of test cases. Then the test cases follow.
- Each test case consists of a single line of input containing 44 space separated integers - X1,Y1,X2,Y2X1,Y1,X2,Y2 - as defined in the problem statement.
Output Format
For each test case, output in a single line the chessboard distance between (X1,Y1)(X1,Y1) and (X2,Y2)(X2,Y2)
Constraints
- 1≤T≤1000
- 1≤X1,Y1,X2,Y2≤105
Subtasks
Subtask #1 (100 points): original constraints
Sample 1:
3 2 4 5 1 5 5 5 3 1 4 3 3
3 2 2
Solution
#include <stdio.h>
#include <limits.h>
#include<stdlib.h>
int main(void)
{
int p;
scanf("%d",&p);
while(p--)
{
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
int a = abs(x1-x2);
int b=abs(y1-y2);
if(a > b)
printf("%d\n",a);
else printf("%d\n",b);
}
return 0;
}