DWITE Online Computer Programming Contest, February 2009, Problem 3
cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, DOS, OS/2 and Windows.
The input will contain 5 sets of input, 2 lines each. The first line of input will be a string representing the current location in the file system. The second will be a path to be taken, relative to the starting location. All strings (including output) will be non-empty and less than 255 characters.
The output will contain 5 lines, each corresponding to the new working directory of the input sets.
You may assume that all directories exist, and that the paths given are valid. For those unfamiliar with traversing file structures on a computer, the key points are:
./
– current directory../
– directory that's a step aboveany_word/
– directory a step below
Example: if the working directory is /one/two/
it means that there is a root directory /
which contains a directory one/
which, in turn, contains another directory two/
. If we were to change directories as follows:
./
– we'd stay where we are:/one/two/
././
– we'd continue to stay in/one/two/
../
– move one above:/one/
../../
– move two above:/
../../../
– move three above. One can't move higher than root, so the result will stay at/
../three/./
– move up one, change directory tothree
, and stay there:/one/three/
Sanity check: the first and last character of your output will always be a forward slash /
.
Sample Input
/
one/two/
/
one/../two/
/
one/../../../two/
/
./one/
/one/two/
.././three/four/../
Sample Output
/one/two/
/two/
/two/
/one/
/one/three/
Problem Resource: DWITE
Comments