早教吧作业答案频道 -->英语-->
求大神帮我看一下这道Codeforces上的ACM题目C.CdandpwdcommandsProblemDescriptionVasyaiswritinganoperatingsystemshell,anditshouldhavecommandsforworkingwithdirectories.Tobeginwith,hedecidedtogowithjusttwocommands:c
题目详情
求大神帮我看一下这道Codeforces上的ACM题目
C.Cd and pwd commands
Problem Description
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.
Input
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.
Output
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.
Sample Input
7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd
4
cd /a/b
pwd
cd ../a/b
pwd
Sample Output
/
/home/vasya/
/home/
/home/petya/
/a/b/
/a/a/b/
Source
Codeforces
C.Cd and pwd commands
Problem Description
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.
Input
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.
Output
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.
Sample Input
7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd
4
cd /a/b
pwd
cd ../a/b
pwd
Sample Output
/
/home/vasya/
/home/
/home/petya/
/a/b/
/a/a/b/
Source
Codeforces
▼优质解答
答案和解析
开始路径为根目录, 一共两种命令pwd,cd
pwd -- 显示当前绝对路径
cd -- 跳转到某个地址 ,两种情况
(1)如果以/开头,表示绝对路径,直接跳转到这个目录
比如cd /a/c ,那么当前目录就是/a/c/
(2)不是以/开头,表示相对路径
比如cd a/cc/dd , pwd 为 /a的话 ==》 /a/a/cc/dd/
如果你用过shell的话应该没问题的.
这道题存粹是考实现啊,没什么技巧啊
pwd -- 显示当前绝对路径
cd -- 跳转到某个地址 ,两种情况
(1)如果以/开头,表示绝对路径,直接跳转到这个目录
比如cd /a/c ,那么当前目录就是/a/c/
(2)不是以/开头,表示相对路径
比如cd a/cc/dd , pwd 为 /a的话 ==》 /a/a/cc/dd/
如果你用过shell的话应该没问题的.
这道题存粹是考实现啊,没什么技巧啊
看了 求大神帮我看一下这道Code...的网友还看了以下:
提示:D-C=0A-B,A-D,D-C,D-E,E-F=1A-D,C-F=2A-B,D-E,E-F 2020-04-06 …
已知a、b、c、d是非零实数,并满足a+b+c−dd=a+b−c+dc=a−b+c+db=−a+b 2020-05-13 …
24 (a+b)/(c+d)=(√a^2+b^2)/√ (c^2+d^2)成立证明:(1)a/b= 2020-05-14 …
现有A,B,C,D四种物质,已知A,B为黑色粉末,C,D为无色气体,A,B在高温下作用能生成D,A 2020-05-17 …
如果正数a,b,c,d满足a+b=cd=4,那么()A.ab≤c+d且等号成立时a,b,c,d的取 2020-07-09 …
用Matlab求解方程组?如何用数值法啊?,a,b,c,d是未知量s1=(a/((4*pi*b*c 2020-07-23 …
A,B,C,D四个数的和为59,问A^2+B^2+C^2+D^2,A^3+B^3+C^3+D^3, 2020-07-28 …
在三角形ABC和三角形A'B'C'中CD,C'D'分别是高,并且AC=A'C;,CD=C'D',∠A 2020-11-28 …
多元一次方程求解a=0.1072(a+b+c+d+e)b=0.041(a+b+c+d+e)c=0.2 2020-12-14 …
请问谁知道用matlab求解多元超越方程组的方法或思路或函数不?形如:a*(1+a+a^3+d+d^ 2020-12-14 …