TJU训练赛—D

来源:互联网 发布:化学反应软件 编辑:程序博客网 时间:2024/04/30 04:17
4081.   God Le wants to know the directory
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 393   Accepted Runs: 134



God Le is the most talented ACMer in the TJU-ACM team.
When he wants to open a file,he can just use his keyboard instead of using his mouse to click.
Why he can do this?Because he uses the cmd.exe. There are many commands in cmd.exe.But God Le is kind of lazy,so he just uses three commands to change the current directory.
"cd dir"(without quotes):put you in a subdirectory.For example,if you are in C:\Programs,typing cd Vim will put you in C:\Programs\Vim.
"Disk(like C,D,etc):"(without quotes):put you in the directory in that Disk that you are in most recently.For example,if you are in C:\Programs,typing D: and C: will put you in C:\Programs.(at the beginning,when you type Disk:,you will be in Disk:\).
"cd .."(without quotes):move you up one directory.So,if you are in C:\Programs\Vim,cd .. moves you to C:\Programs.
Because God Le is very smart,he won't go to the directory that is not existed. Now,given a sequence of commands,God Le wants to know the current directory.
One thing that you should know is that God Le's computer only have four disks C,D,E,F.
HINT I:The initial directory is C:\users\godle
HINT II:every subdirectory is only a string contains no more than 10 lower-case letters.

Input

There are mulit cases.Each case begins with an integer m(1 ≤ m ≤ 10^3)means the operations.Next there are m lines.Each line contains a command.

Output

For each command,print the current directory.You can get more hints from the sample.

Sample Input

5cd ..D:cd ..cd abcC:

Sample Output

C:\usersD:D:D:\abcC:\users
【分析】
读各种命令输出...模拟题

注意一下如果当前在 C:\111 

进行

D: 

C: 

操作回到C:\111而不是C:\。

另外注意反斜杠是'\\'  


【代码】
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int main()  {  string ans[5],s,t;    int n;while(~scanf("%d",&n))      {          int now=0;ans[0]= "C:\\users\\godle";ans[1]= "D:";ans[2]= "E:";ans[3]= "F:";for(int i=0;i<n;i++)          {              cin>>s;if(s=="cd")              {              cin>>t;                if(t=="..")                  {                  int j;                     for(j=ans[now].length()-1;j>=0;j--)                          if(ans[now][j]=='\\')                              break;                      if(j>=0)  ans[now].erase(j,ans[now].length()-j);                }                  else                  ans[now]+="\\"+t;                }              if(s=="C:") now=0;            if(s=="D:") now=1;            if(s=="E:") now=2;            if(s=="F:") now=3;cout<<ans[now]<<endl;         }      }      return 0;  }  


原创粉丝点击