#C10279. Valid Knight Move Checker
Valid Knight Move Checker
Valid Knight Move Checker
In chess, a knight moves in an L-shape. That is, if a knight is on a square, it can move to a square such that the differences in the column and row positions ((dx) and (dy)) satisfy either (dx=2) and (dy=1) or (dx=1) and (dy=2).
Given a list of moves in algebraic notation with the format start->end
(for example, a1->b3
), your task is to determine for each move if it is a valid knight move on a standard 8(\times)8 chessboard. The input will consist of a number of moves, and you must output VALID
if the move is legal for a knight or INVALID
if not.
inputFormat
The input is given via standard input (stdin) and is formatted as follows:
T
move_1
move_2
...
move_T
where T
denotes the number of moves, and each move
is a string representing a move in the format xy->zw
. Here, x
and z
are lowercase letters from 'a' to 'h' (representing columns) and y
and w
are digits from '1' to '8' (representing rows).
outputFormat
For each move provided in the input, print a line containing either VALID
if the move is a valid knight move or INVALID
otherwise. The output should be directed to standard output (stdout).## sample
4
a1->b3
a1->c2
h8->g6
b1->c2
VALID
VALID
VALID
INVALID
</p>