Let's imagine a chessboard, the squares on which are marked with coordinates. The coordinates are numbers between 1 and 8 inclusively. The first number indicates a column, the second one indicates a row.
The chess king can stand on any square and can move one step horizontally, vertically, or diagonally in any direction within the board.
The input will contain the coordinates on which the king is located. You should figure out and print how many moves the figure can make: for example, from the position (1, 8), the king can make only 3 moves (right, down, diagonally).
Here's the steps you can follow:
Start by reading the coordinates of the king from the input.
To determine the number of possible moves for the king, consider all possible directions: horizontally (left and right), vertically (up and down), and diagonally (up-left, up-right, down-left, down-right).
Iterate through each possible direction and check if the king can move to the corresponding square. Make sure to verify that the new position is within the bounds of the chessboard (coordinates between 1 and 8 inclusively).
Keep track of the count of valid moves.
Finally, print out the total count of valid moves.