As a CS student, you must be familiar with command-line shell, especially the basic concept of working directory and th cd
command. In fact, modern shells (even Windows' Command Propmt included!) maintain a stack (a container that holds FILO (First-In, Last-Out) principle) of directories so that we could traverse among directories easily. For the purpose of understanding the mechanism well, let's simulate the fundamental behaviors.
The paths in Unix-like OS could be divided into 2 types:
/
and the other directories within the path (if any) are splited by /
./
.
~
means ones's home directory. Here suppose we're running as super user root thus it equals /root
..
denotes the current working directory...
represents the parent directory of current working directory. Note that if current working directory is root directory, then it's still the root directory.For instance, ~/.ssh
could be expanded to /root/.ssh
.
The commands involved are listed below. Though some details vary among shells (e.g., bash or zsh) and this problem is mainly based on bash, slight difference might exist. These commands below support many other useful parameters yet too complex to implement.
cd
. Change directory.
-
, change back to previous ("old") working directory.pwd
. Print working directory.
pushd
. Push directory into stack.
cd
.popd
. Pop diectory from stack.
dirs
.
Initally, the working directory is the home directory, /root, and we set the old working directory same.
There would be at most 5000 commands. The name of each directory consists of only English letters and numbers, and the length doesn't exceed 10.
About 20% of the testcases contain only absolute paths. Another approximate 30% of the testcases don't containe paths related to ..
parent of current working directory.
Assume that all paths are valid.
Already mentioned in above description. Please note that for dirs
command, redudant space at the end of line is not allowed.