C. Cd and pwd commands

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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

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

Sample Output

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

HINT

题意

俩操作

cd 改变路径

pwd输出路径

..就是返回到上一级

题解:

模拟一下就好了~

代码

#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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 1050005
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n,z;
string c,s,p="/";
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>c;
if(c=="cd")
{
cin>>c;
c+="/";
if(c[]=='/')
{
p="/";
z=;
}
for(int j=z;j<c.size();j++)
{
if(c[j]=='.'&&c[j+]=='.'&&c[j+]=='/')
{
int k=p.size()-;
p[k+]='\0';
p.resize(p.size()-);
while(p[k]!='/')
{
p[k]='\0';
k--;
p.resize(p.size()-);
}
j+=;
}
else
{
p+=c[j];
} }
z=;
}
if(c=="pwd")
cout<<p<<endl;
} }

VK Cup 2012 Qualification Round 1 C. Cd and pwd commands 模拟的更多相关文章

  1. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  2. VK Cup 2012 Qualification Round 1---C. Cd and pwd commands

    Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟

    C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...

  4. VK Cup 2012 Qualification Round 1 E. Phone Talks —— DP

    题目链接:http://codeforces.com/contest/158/problem/E E. Phone Talks time limit per test 3 seconds memory ...

  5. VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland

    今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...

  6. VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树

    题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...

  7. VK Cup 2016 - Qualification Round 2 D. Three-dimensional Turtle Super Computer 暴力

    D. Three-dimensional Turtle Super Computer 题目连接: http://www.codeforces.com/contest/638/problem/D Des ...

  8. VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs

    C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...

  9. VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland 水题

    B. Making Genome in Berland 题目连接: http://www.codeforces.com/contest/638/problem/B Description Berlan ...

随机推荐

  1. LR之脚本调试

    1.概述 2.Animated run和Non-animated run 3.调试小技巧 4.日志设置

  2. Java之--Java语言基础组成—函数

    Java语言基础组成-函数 Java语言由8个模块构成,分别为:关键字.标识符(包名.类名.接口名.常量名.变量名等).注释.常量和变量.运算符.语句.函数.数组. 本片主要介绍Java中的函数,函数 ...

  3. 把两个DataTable连接起来,相当于Sql的Inner Join方法

    在C#中把两个DataTable连接起来,相当于Sql的Inner Join方法 作者:浪漫十一狼在下面的例子中实现了3个Join方法,其目的是把两个DataTable连接起来,相当于Sql的Inne ...

  4. VC远控(二)连接Server端及密码验证

    首先服务端是一个win32console应用程序. 在建立项目的时候需要勾选MFC 套接字的初始化同客户端相似: //对套接字进行初始化 WSADATA wsadata; WORD ver = MAK ...

  5. 前端面试题(JS篇)

    原题地址:http://handyxuefeng.blog.163.com/blog/static/454521722013111714040259/ 好吧,最近打算换工作,所以关注比较多的是面试题, ...

  6. DOM笔记(十):JavaScript正则表达式

    一.RegExp ECMAScript通过RegExp类型类支持正则表达式,语法和Perl类似: var exp = /pattern/flags; patternb部分是任何简单的或复杂的正则表达式 ...

  7. Axure中继器基础教程(增行、删当前、标记、全部、规则行) Mark

    ---恢复内容开始--- 一.中继器的新增行 中继器所显示的列表项与中继器的数据集有关,默认情况下是一一对应的.也就是说,中继器数据集中有多少行数据,那么,列表项就有多少个. 那么,我们能不能通过新增 ...

  8. javascript常用的小知识

    1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...

  9. 第一百九十三天 how can I 坚持

    我以为我是谁. 你可以记录你今天看了电影 也可以记录你最近在听什么歌 但这都会成为回忆 .  ---oncelife 快受不了了啊.咋办. 今天看了<滚蛋吧,肿瘤君>,还看了<那山那 ...

  10. Ubuntu下实用命令收集 --新增 删除 环境变量

    1. 关闭防火墙: sudo ufw disable 2. 设置IPV4地址和网关: ifconfig eth0 up %s netmask %s route del default gw 192.1 ...