#C122. Spaceship Module Management
Spaceship Module Management
Spaceship Module Management
You are in charge of a spaceship management system. Your task is to simulate the commands to create spaceships and add various modules to them.
Each command is given in a specific format. The first command for a spaceship is of the form:
Spaceship <name>
This creates a spaceship with the given name.
Subsequent commands add modules to an existing spaceship. The module commands can be one of the following:
- Engine:
Engine <spaceship_name> <module_name> <space> <thrust>
- CargoBay:
CargoBay <spaceship_name> <module_name> <space> <storage_volume>
- Laboratory:
Laboratory <spaceship_name> <module_name> <space> <research_capacity>
The overall output should list all spaceships (sorted in lexicographical order by their names) and, for each spaceship, list all its modules in the order they were added. For each module, display the type and the corresponding properties.
More formally, if we denote the spaceship's name as S and its list of modules as M, the output has the following structure:
\( Output = S + \sum_{m \in M} \text{Formatted Module String} \)
where the formatted module string is given as:
- For an Engine module:
Engine <module_name> space=\(s\) thrust=\(t\)
- For a CargoBay module:
CargoBay <module_name> space=\(s\) storage_volume=\(v\)
- For a Laboratory module:
Laboratory <module_name> space=\(s\) research_capacity=\(r\)
Note: The input is read from standard input and the output must be written to standard output.
inputFormat
The first line contains an integer n
representing the number of commands. The following n
lines each contain a command.
Each command is a space-separated string formatted as described in the problem statement.
outputFormat
Print the state of the spaceship management system. For each spaceship (sorted by name), print its name followed by the list of modules added to it. Each module is printed in a new line, indented by two spaces, and formatted according to its type.
## sample7
Spaceship Apollo
Engine Apollo engine1 100 300
CargoBay Apollo cargo1 200 5000
Spaceship Orion
Laboratory Orion lab1 150 400
Engine Orion engine2 200 500
CargoBay Orion cargo2 250 6000
Apollo
Engine engine1 space=100 thrust=300
CargoBay cargo1 space=200 storage_volume=5000
Orion
Laboratory lab1 space=150 research_capacity=400
Engine engine2 space=200 thrust=500
CargoBay cargo2 space=250 storage_volume=6000
</p>