首页 > 其他 > 详细

C. Cd and pwd commands

时间:2019-08-18 01:24:05      阅读:122      评论:0      收藏:0      [点我收藏+]

题目链接: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 }

 

C. Cd and pwd commands

原文:https://www.cnblogs.com/-Ackerman/p/11371030.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!