CF158C.Cd and pwd commands
普及/提高-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
瓦西娅正在编写一个操作系统 Shell,该 Shell 需要支持目录操作命令。作为起点,他决定仅实现两条命令:cd(切换当前目录)和 pwd(显示当前目录)。
瓦西娅的操作系统中的目录采用传统的树形层次结构。存在唯一的根目录,用斜杠字符 / 表示。其余每个目录都有一个名称——一个由小写拉丁字母组成的非空字符串。每个目录(根目录除外)都有一个父目录——即包含该目录的目录。父目录以 .. 表示。
命令 cd 接收一个参数,即文件系统中的一条路径。该命令将当前目录切换为路径所指定的目录。路径由若干目录名组成,各目录名之间以斜杠 / 分隔。目录名可以是 ..,表示向上移动一级至父目录。.. 可出现在路径的任意位置,且可多次出现。若路径以斜杠 / 开头,则视为绝对路径,即从根目录开始解析并切换至指定目录;若参数以目录名(或 ..)开头,则视为相对路径,即从当前目录开始解析并切换至指定目录。
命令 pwd 应显示当前目录的绝对路径,该路径中不得包含 ..。
初始时,当前目录为根目录。所有在任意 cd 命令中被显式提及或间接涉及的目录均视为存在。保证不会尝试进入根目录的父目录(即不会出现超出根目录的 .. 操作)。
输入格式
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.
输入数据的第一行包含一个整数 $ n ( 1 \leq n \leq 50 $)—— 表示命令的条数。
接下来是 $ n $ 行,每行包含一条命令。每条命令要么是 pwd,要么是 cd 后跟一个以空格分隔的非空参数。
cd 命令的参数仅包含小写拉丁字母、斜杠 / 和点号 .;两个斜杠不会连续出现;点号仅作为父伪目录(即 ..)的名称出现。cd 命令的参数不以斜杠结尾,除非该参数本身仅为一个斜杠 /(此时表示根目录)。cd 命令参数的长度在 $ 1 $ 到 $ 200 $ 个字符之间(含端点)。
文件系统中的目录可以具有相同的名称。
输出格式
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.
对于每个 pwd 命令,您应输出给定目录的完整绝对路径,路径以斜杠 / 结尾。该路径必须以斜杠 / 开头,并包含从根目录到当前文件夹的、按嵌套顺序排列的一系列由斜杠 / 分隔的目录名。路径中不得包含任何英文句点 .。
输入输出样例
输入#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/
输入解题思路,AI测评打分。不知道怎么写?