#K13686. File System Simulation
File System Simulation
File System Simulation
You are required to simulate a basic file system that supports three operations:
mkdir path
: Create a new directory at the specified absolute path.rmdir path
: Remove the specified directory along with all of its subdirectories.ls path
: List all immediate subdirectories of the given directory in lexicographical order.
The file system is initially empty. All paths are given as absolute paths starting with a /
. It is guaranteed that the commands are valid and follow the proper ordering (e.g. a directory is created before any operations on it are performed).
Note: When performing the ls
operation, if there are no subdirectories, output an empty line.
The operations are executed in the order they are given. You must process each command accordingly and print the output for each ls
command to the standard output.
For any mathematical expressions, use LaTeX formatting. For instance, if you need to show the lexicographical order, you can write it as: \(a \leq b\).
inputFormat
The first line contains an integer Q
representing the number of commands.
Each of the following Q
lines contains a command in one of the following formats:
mkdir path
rmdir path
ls path
All commands are provided via standard input (stdin
).
outputFormat
For each ls
command, print a single line containing the names of the immediate subdirectories of the given directory, separated by a single space, in lexicographical order. If there are no subdirectories, print an empty line.
The output should be printed to standard output (stdout
).
7
mkdir /home
mkdir /home/user
mkdir /home/user/docs
mkdir /home/user/music
ls /home
rmdir /home/user/docs
ls /home/user
user
music
</p>