#K45487. File System Manager Simulation
File System Manager Simulation
File System Manager Simulation
You are given a series of commands to simulate a simplified file management system. The system supports three commands:
- CREATE /path/to/directory: Creates a new directory at the specified path. If intermediate directories do not exist, they are created automatically.
- DELETE /path/to/directory: Deletes the directory at the specified path, along with all its subdirectories. If the directory does not exist, ignore the command.
- MOVE /path/from /path/to: Moves the directory from the first path to be a subdirectory of the directory at the second path. If any path does not exist (for source), ignore the command. In the destination, missing intermediate directories should be created.
The simulated file system is represented as a nested list structure. The representation follows this recursive format:
\[
node = [\texttt{}, child_1, child_2, \ldots, child_k]
\]
For the root, the name is the empty string ""
. For example, after executing certain commands the file system may look like:
["", ["d", ["g", ["h", ["a", ["b", ["c"]]]]]]]
Your task is to implement the file system manager. The input will be provided via stdin
as a multiline string of commands and you must print the final directory structure to stdout
in the nested list format described above.
The commands in the input are separated by newline characters. All directory paths start with a forward slash (/
).
Note: In your implementation, when you need to represent a mathematical formula (if applicable), use the LaTeX format. In this problem, the operations and data model can be conceptually summarized as a recursion:
[ T(n) = T(n_1) + T(n_2) + \cdots + T(n_k) + O(1) ]
inputFormat
The input is read from stdin
and consists of multiple lines. Each line contains one command in one of the following formats:
CREATE /path/to/directory
DELETE /path/to/directory
MOVE /path/from /path/to
Commands are executed in the order they are given.
outputFormat
Print to stdout
a single line representing the final file system as a nested list structure in Python-like notation. For example:
["", ["d", ["g", ["h", ["a", ["b", ["c"]]]]]]]## sample
CREATE /a/b/c
CREATE /d/e/f
MOVE /a /d/g/h
DELETE /d/e
["", ["d", ["g", ["h", ["a", ["b", ["c"]]]]]]]