Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int x, y, xx, yy;
int main() {
scanf("%d %d %d %d", &x, &y, &xx, &yy);
if(x == xx || y == yy)
printf("1 ");
else
printf("2 ");
if((x + y) % 2 != (xx + yy) % 2)
printf("0 ");
else if(abs(x - xx) == abs(y - yy))
printf("1 ");
else
printf("2 ");
int k = abs(x - xx) + abs(y - yy);
if(abs(x - xx) < abs(y - yy))
k -= abs(x - xx);
else
k -= abs(y - yy);
printf("%d\n", k);
return 0;
}
Copy The Code &
Try With Live Editor
Input
4 3 1 6
Output
2 1 3
Demonstration
Codeforces Solution-Rook, Bishop and King-Solution in C, C++, Java, Python