#C10471. Robot Cleaner on a 5x5 Grid

    ID: 39680 Type: Default 1000ms 256MiB

Robot Cleaner on a 5x5 Grid

Robot Cleaner on a 5x5 Grid

You are given a 5x5 grid where each cell is initially marked with a dot ('.'). A robot cleaner starts at the top-left corner of the grid, which corresponds to the coordinate \((0,0)\). The robot receives a series of movement commands as input. The valid commands are:

  • N: Move north (up)
  • S: Move south (down)
  • E: Move east (right)
  • W: Move west (left)

If a command would cause the robot to leave the grid, the robot ignores that command. After processing all commands, mark the robot's final position with an "R", and leave all other positions as dots.

Your task is to simulate the robot's movement and print the final state of the grid. Use stdin to read the commands and stdout to display the output.

inputFormat

The input consists of a single line containing a sequence of commands separated by spaces. Each command is one of N, S, E, or W. If there are no commands, the line may be empty.

outputFormat

Output the final grid state as five lines with exactly five characters on each line. Each line represents a row of the grid, showing the position of the robot (marked by 'R') and dots ('.') for the other cells.## sample

N E E S S S W N
.....

..... .R... ..... .....

</p>