The path to a file on a computer can be given as either an absolute path
or relative path
. An absolute path dictates the folders to traverse starting from the drive letter. For example, C:/Users/Kevin/documents/important
is an absolute path. A relative path is a path that starts from the current folder the user is in or the command is executed from. For example, if the current folder was C:/Users
and the relative path Jonathan/videos/osu
was accessed, the absolute path for the resulting folder is C:/Users/Jonathan/videos/osu
. Given the file structure of a computer, process a sequence of folder access commands.
Input Specification
The first line of input contains representing the number of folders on the computer.
The next lines of input each represent a folder.
- Each line will begin with a sequence of spaces.
- It will then be followed by a unique sequence of no more than 100 lowercase letters. This indicates the folder name.
- This folder is a child of the first folder given before it that has exactly 2 less spaces than this one. Consider the sample for more details.
- The first folder will always have 0 spaces and will be titled
root
. This folder has no parent.
The next line of input contains representing the number of commands that must be processed.
The next lines contain a command.
- If the command is
ls
, all children of the current folder must be listed in the order in which they were added. - Otherwise, the command begins with
cd
and contains an argument after a space.- This argument indicates that the child of the current folder titled with the argument should be accessed. The child folder is the new current folder.
- The argument may be
..
. This indicates that the parent folder of the current folder should be accessed.
- The first command is always
cd root
to set theroot
folder as the current folder.
Output Specification
For every ls
command, list each child folder of the current folder on a new line in the order in which they appeared. If the folder has no children, do not print anything.
Sample Input
7
root
pics
vacation
selfies
documents
work
school
5
cd root
cd pics
ls
cd ..
ls
Sample Output
vacation
selfies
pics
documents
school
Explanation of Sample
The file structure can be visualized as follows:
root
├── pics
│ ├── vacation
│ └── selfies
│
├── documents
│ └── work
│
└── school
First, the pics
folder under root
is accessed then all children are printed. The children of pics
are vacation
and selfies
. Then, the parent folder root
is accessed then all children of it are printed. The children of root
are pics
, documents
, and school
.
Comments