#C14860. File System Simulation
File System Simulation
File System Simulation
You are required to simulate a simple file system. The file system initially is empty. You need to process a series of operations that create directories and add files along with their integer values. The operations are of two types:
mkdir <path>
: Create a directory at the specified absolute path. Intermediate directories should be created if they do not exist.addPath <path> <value>
: Create a file at the specified absolute path with an associated integer value. Intermediate directories should be created if necessary. If the path already exists (either as a file or directory), it should be overwritten with the file containing the new value.
After processing all operations, output all file paths (i.e. paths created via the addPath
operation) and their corresponding values. The output should list the paths in lexicographical order (i.e. according to standard string order). Each output line should be in the format:
Remember that paths are absolute and begin with a forward slash /
.
inputFormat
The first line contains an integer n
, the number of operations. Each of the next n
lines contains an operation in one of the following formats:
mkdir /path/to/directory
addPath /path/to/file value
Note: path
is an absolute path beginning with a '/'.
outputFormat
Output all file paths along with their assigned integer values in lexicographical order of the full path. Each line should contain a file path and its value separated by a space. Do not output directories that have no associated file value.## sample
4
mkdir /a/b/c
mkdir /a/b/d
addPath /a/b/c/file1 10
addPath /a/b/d/file2 20
/a/b/c/file1 10
/a/b/d/file2 20
</p>