Hurray! Your first shift went well and you are still alive. Your owner was satisfied with the clean room, but all that dirt clogged your brush. Until he buys a replacement, he just wants you to patrol the living room and report back.
Your bumper still works the same way. A command that would take you out of the room is refused outright, and you wait for the next one. You no longer clean anything; you only move. The rest of the rules remain the same:
STOP, it ends your shift immediately. Any commands that come afterwards are skipped.Note: you can try using while-loop when solving this problem.
The first line is five integers. The first one is the number of command you will received com . The next two are R rows and C columns. Rows are numbered 0 to R-1 from top to bottom, columns 0 to C-1 from left to right; basically 0-indexed. The last two are your initial position in the living room sr -th row and sc -th column.
The next com lines are either:
<dir> <steps> where <dir> is one of N , S , E , W , which mean north, south, east, and west correspondingly. <steps> is a positive integer of how many steps you will take within the grid.STOP which means you need to discard all the next commands.Constraints
com ≤ 100R, C ≤ 100sr < R, 0 ≤ sc < C<dir> is one of N, S, E, W<steps> ≤ 100First line of output is your fr final row and fc column in the grid. The next line is the number of how many commands you have skipped (including the commands that come after the command STOP if applicable).