PROBLEM 96
Hard

Chess Bishop Move

Programming Basics · C++

</>
STATUS Not solved

TASK

Problem

#96

Given two different chessboard squares `(x1,y1)` and `(x2,y2)`, print `YES` if a bishop can move from the first to the second in one legal move; otherwise print `NO`.

EXAMPLE

Example

Input
1 1 2 2
Output
YES

LIMITS

Constraints

1 ≤ x1, y1, x2, y2 ≤ 8; the two squares are different.
📖
LEARN Theory for this problem
+

These exercises combine arithmetic, comparisons, and small branches. Keep each condition explicit and easy to verify.

Connection to “Chess Bishop Move”: here, intermediate values are best kept in named variables so the formula stays readable and data types remain clear.

💡
NEED HELP? Hints
+

['Break the task into a few simple checks instead of compressing everything into a clever expression.', 'After solving “Chess Bishop Move”, verify the algorithm on your own small example and on an allowed boundary case. Print only the required result with no extra text.']

ANSWER Solution
+
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
    long long x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << ((llabs(x1-x2)==llabs(y1-y2))?"YES":"NO") << '\n';
    return 0;
}