300827: CF158C. Cd and pwd commands

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cd and pwd commands

题意翻译

你需要实现类似 Unix / Linux 下的 `cd` 和 `pwd` 命令。 一开始,用户处于根目录 `/` 下。 对于 `cd` 命令,它的作用是跳转到某个路径。路径有相对路径和绝对路径,相对路径以文件夹名开头,表示当前目录下的文件夹,绝对路径以 `/` 开头,表示根目录下的文件夹。同时,`..` 文件夹表示上一层文件夹。 对于 `pwd` 命令,你需要输出当前所在的绝对路径。 保证输入数据中所有的文件夹都存在。

题目描述

Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory). Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..". The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one. The command pwd should display the absolute path to the current directory. This path must not contain "..". Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory.

输入输出格式

输入格式


The first line of the input data contains the single integer $ n $ ( $ 1<=n<=50 $ ) — the number of commands. Then follow $ n $ lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names.

输出格式


For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.

输入输出样例

输入样例 #1

7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd

输出样例 #1

/
/home/vasya/
/home/
/home/petya/

输入样例 #2

4
cd /a/b
pwd
cd ../a/b
pwd

输出样例 #2

/a/b/
/a/a/b/

Input

题意翻译

你需要实现类似 Unix / Linux 下的 `cd` 和 `pwd` 命令。 一开始,用户处于根目录 `/` 下。 对于 `cd` 命令,它的作用是跳转到某个路径。路径有相对路径和绝对路径,相对路径以文件夹名开头,表示当前目录下的文件夹,绝对路径以 `/` 开头,表示根目录下的文件夹。同时,`..` 文件夹表示上一层文件夹。 对于 `pwd` 命令,你需要输出当前所在的绝对路径。 保证输入数据中所有的文件夹都存在。

加入题单

上一题 下一题 算法标签: