日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > 互聯(lián)網(wǎng) > VK Cup 2012 Qualification Round 1---C. Cd and pwd commands

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

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-11-18 09:02:39 閱讀次數(shù):3219次

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

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 test(s)
input
7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd
output
/ /home/vasya/ /home/ /home/petya/
input
4 cd /a/b pwd cd ../a/b pwd
output
/a/b/ /a/a/b/





解題思路:用字符串操作摹擬樹。 找絕對(duì)路徑。





AC代碼:

#include <iostream> #include <cstdio> #include <string> using namespace std; int main(){ // freopen("in.txt", "r", stdin); int n; string cmd, cur, ans, tt; while(cin>>n){ ans = "/"; for(int i=0; i<n; i++){ cin>>cmd; if(cmd == "cd"){ cin>>cur; cur += '/'; for(int j=0; j<cur.size(); j++){ tt += cur[j]; if(cur[j] == '/'){ if(tt == "/") ans = tt; else if(tt == "../"){ int k; for(k=ans.size()⑴; ans[k⑴]!='/'; k--) ; ans.resize(k); } else ans += tt; tt = ""; } } } else{ cout<<ans<<endl; } } } return 0; }


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 日本h视频 | 成人永久aaa | 色先锋影院 | 九九热精品视频 | 国产精品第52页 | 天堂在线免费观看 | 成年网站在线观看 | 日本免费网 | 国产91精品久久久久久久 | 国产一区二区自拍视频 | 欧美成人在线免费 | 欧美精选一区二区 | 国产精品视频专区 | 日韩欧美国产一区二区三区 | 精品66 | 99re视频| 亚洲视频在线视频 | 国产精品久久久久久久久免费 | 色综合久久综合网 | 精品视频在线观看 | 91精品国产九九九久久久亚洲 | 国产一区二区在线播放 | 亚洲狠狠干 | 色丁香婷婷| 国产精品久久久久毛片软件 | 日本久久久一区二区三区 | 国产原创精品视频 | 久久久久久久久久国产精品 | 福利久久 | 日韩欧美第一页 | 国产黄 | 色淫视频| 欧美夜夜 | chinesexxxx国产麻豆 | 欧洲久久 | 毛片天堂 | 久一视频在线观看 | 久久国产精品视频 | 国产精品久久久久久影视 | a级片在线免费观看视频 | 色一情一乱一伦一区二区三区 |