#C8790. Nested File Structure
Nested File Structure
Nested File Structure
You are given a list of Unix-style file paths. Your task is to construct a hierarchical nested dictionary (i.e. a JSON object) that represents the file system. For example, the file path home/user/file1.txt
should be represented as \{\text{home}: \{\text{user}: \{\text{file1.txt}: \{\}\}\}\}.
If the list is empty, return an empty dictionary {}
. Handle multiple file paths appropriately, merging common directory parts.
inputFormat
The input is read from standard input (stdin). The first line contains an integer n
— the number of file paths. Each of the following n
lines contains a file path in Unix format (directories separated by '/').
outputFormat
Print to standard output (stdout) the nested dictionary in JSON format that represents the directory structure. An empty list of file paths should result in output {}
.
1
home/user/file1.txt
{"home":{"user":{"file1.txt":{}}}}