加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C. Cd and pwd commands

发布时间:2020-12-16 09:19:29 所属栏目:百科 来源:网络整理
导读:题目链接:http://codeforces.com/problemset/problem/158/C ? 题意: 模拟对文件路径的操作。 ? 1 #include iostream 2 #include algorithm 3 #include stdlib.h 4 #include string 5 #include string .h 6 #include set 7 #include queue 8 #include stdbo

题目链接:http://codeforces.com/problemset/problem/158/C

?

题意:

模拟对文件路径的操作。

?

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdlib.h>
 4 #include <string>
 5 #include <string.h>
 6 #include <set>
 7 #include <queue>
 8 #include <stdbool.h>
 9  
10 #define LL long long
11 using namespace std;
12 const int maxn = 1e6 + 10;
13  
14  
15 int main(){
16     int n;
17     scanf("%d",&n);
18     string s,p = "/",temp;
19     for (int i=0;i<n;i++){
20         cin >> s;
21         if (s == "cd"){
22             cin >> s;
23             s += "/";
24             for (int j=0;j<s.length();j++){
25                 temp += s[j];
26                 if (s[j] == /){
27                     if (temp == "/"){
28                          p = temp;
29                     }
30                     else if (temp == "../"){
31                         int k;
32                         for (k=p.length()-1;p[k-1]!=/;k--)
33                             ;
34                         p.resize(k);
35                     }
36                     else {
37                         p += temp;
38                     }
39                     temp = "";
40                 }
41             }
42         }
43         else if (s == "pwd"){
44             cout << p << endl;
45         }
46     }
47 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读