#K62567. Knight Moves

    ID: 31560 Type: Default 1000ms 256MiB

Knight Moves

Knight Moves

Given the current position of a knight on an 8×8 chessboard, compute all possible moves the knight can make in one turn. The knight moves in an L-shape: two squares in one direction and one square perpendicular to that direction. All valid moves should be output in standard chess notation and sorted in lexicographical order. The mathematical formulation for a knight's move is as follows: $$ (x,y) \to (x+\Delta x, y+\Delta y) $$ where (\Delta x) and (\Delta y) can be one of the pairs in ({(-2, -1), (-1, -2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)}).

inputFormat

A single line read from stdin containing a two-character string. The first character (a-h) represents the file and the second character (1-8) represents the rank of the knight's current position (e.g., "e4").

outputFormat

A single line printed to stdout containing valid knight moves, sorted in lexicographical order and separated by spaces.## sample

e4
c3 c5 d2 d6 f2 f6 g3 g5

</p>