VK Cup Qualification Round 1 C. Cd and PWD commands simulation

Source: Internet
Author: User

C. Cd and PWD commands

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/problemset/problem/158/C

Descriptionvasya is writing an operating system shell, and it should has commands for working with directories. To begin with, he decided to go with just-commands:cd (change the current directory) and PWD (Display the current dir Ectory).

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 are 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 is used in any place of the the path, maybe several times. If The path begins with a slash, it's considered to being an absolute path, that's, the directory changes to the specified One, starting from the root. If The parameter begins with a directory name (or ".."), it's considered to being a relative path, that's, the directory Ch Anges 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 is considered to exist. It is guaranteed this 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 the 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, both slashes cannot go consecutively, do TS occur only as the name of a parent pseudo-directory. The command parameter CD does isn't end with a slash, except when it's the only symbol that points to the root directory. The command parameter have a length from 1 to characters, inclusive.

The directories in the file system can has the same names.

Output

For each command pwd 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 roo T to the current folder. It should contain no dots.

Sample Input

7
Pwd
Cd/home/vasya
Pwd
Cd..
Pwd
CD vasya/. /petya
Pwd

Sample Output

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

HINT

Test instructions

Two operations

CD Change Path

PWD Output Path

.. is to return to the upper level.

Exercises

Just a mock-up, please.

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 1050005#defineMoD 10007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************intn,z;stringc,s,p="/";intMain () {CIN>>N;  for(intI=1; i<=n;i++) {cin>>C; if(c=="CD") {cin>>C; C+="/"; if(c[0]=='/') {p="/"; Z=1; }             for(intJ=z;j<c.size (); j + +)            {                if(c[j]=='.'&&c[j+1]=='.'&&c[j+2]=='/')                {                    intK=p.size ()-2; P[k+1]=' /'; P.resize (P.size ()-1);  while(p[k]!='/') {P[k]=' /'; K--; P.resize (P.size ()-1); } J+=2; }                Else{p+=C[j]; }} z=0; }        if(c=="pwd") cout<<p<<Endl; }}

VK Cup Qualification Round 1 C. Cd and PWD commands simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.