#C3708. Room Navigation Simulator
Room Navigation Simulator
Room Navigation Simulator
You are given a simulation of a text-based adventure game in which a player navigates through an interconnected network of rooms. The simulation begins in a starting room and processes a list of movement commands. Each command is one of the four valid directions: north, south, east, or west.
When a valid movement command is issued, if the corresponding exit from the current room does not already lead to another room, a new room is created and connected appropriately. If the exit already exists, the player simply moves to that room. If an invalid direction is encountered, the program must immediately print Invalid direction
and terminate without processing further commands.
After processing all commands successfully, output the total number of unique rooms that have been created (including the starting room).
inputFormat
The first line contains an integer n representing the number of movement commands. The following n lines each contain one command: a string that is one of north
, south
, east
, or west
.
All input is given via standard input (stdin).
outputFormat
If all commands are valid, output a single integer representing the total number of unique rooms created (including the starting room) to standard output (stdout).
If an invalid command is encountered, output exactly Invalid direction
(without quotes) and terminate immediately.
4
north
east
south
west
5
</p>