#C5061. File System Simulator
File System Simulator
File System Simulator
You are required to implement a simple file system that supports two types of operations: create
and get
. The create
operation attempts to create a new path with an associated integer value. A path can only be created if it does not exist already and its parent directory exists (except when the path is at the root level). The get
operation returns the integer value stored at the specified path, or -1
if the path does not exist.
The input is given via standard input (stdin) and consists of a number of operations. For each get
operation, output the result on a separate line using standard output (stdout).
inputFormat
The first line contains an integer n, the number of operations. Each of the following n lines contains one operation, which can be one of the following:
create /path value
- Create a new path with the given integer value. The creation succeeds only if the path does not already exist and the parent directory exists (if applicable).get /path
- Retrieve and output the value associated with the given path. If the path does not exist, output-1
.
outputFormat
For each get
operation, output the corresponding integer result on its own line. If a path does not exist, output -1
.
5
create /a 1
create /a/b 2
get /a
get /a/b
get /c
1
2
-1
</p>