Movement’s direction

Given two points (x1, y1) and (x2, y2) in a two-dimensional plane, if we
move in a straight line from the first to the second point we advance in
one of the following 8 directions: N (north), S (south), E (east), W
(west), NE (northeast), NW (northwest), SE (southeast), SW (southwest).
For example:

- If we move from (0, 0) to (0, 5) we advance in the N direction;

- If we move from (0, 5) to (0, 0) we advance in the S direction;

- If we move from (0, 0) to (3, 4) we advance in the NE direction;

- If we move from (3, 4) to (0, 0) we advance in the SW direction.

Given a sequence of pairs of points, we want to know, for each pair, the
direction in which we move going from the first to the second point.

Input

The input starts with a non-negative integer n. Then, it follows a
sequence of n quartets of integers x1 y1 x2 y2 representing the pair of
points (x1, y1) and (x2, y2). Assume that (x1, y1) and (x2, y2) are
different.

Output

For each pair of points (x1, y1) and (x2, y2) in the input sequence, the
program outputs the direction in which we move when going from (x1, y1)
to (x2, y2). Follow the format of the examples.

Problem information

Author: Emma Rollón

Generation: 2026-01-25T22:29:10.921Z

© Jutge.org, 2006–2026.
https://jutge.org
