File tree 1 file changed +125
-0
lines changed
1 file changed +125
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include<iostream>
2
+ #include<string>
3
+ #include<stack>
4
+ #include<vector>
5
+ #include<sstream>
6
+ using namespace std;
7
+ int p;
8
+ string a;
9
+
10
+ string standard(string temp)
11
+ {
12
+ string ans;
13
+ int flag=0;
14
+ for(unsigned int i=0;i<temp.size();i++)
15
+ {
16
+ if(temp[i]=='/'&&flag==0)
17
+ {
18
+ ans=ans+temp[i];flag=1;
19
+ }
20
+ else if(temp[i]!='/')
21
+ {
22
+ ans=ans+temp[i];flag=0;
23
+ }
24
+ }
25
+ return ans;
26
+ }
27
+
28
+ void check(string str)
29
+ {
30
+ string ans;
31
+ if(str.size()==0)
32
+ {
33
+ cout<<a<<endl;
34
+ return ;
35
+ }
36
+ if(str[0]!='/')//从根开始
37
+ str=a+"/"+str;
38
+ /*
39
+ vector<string>q;
40
+ for(unsigned int i=0;i<str.size();i++)
41
+ {
42
+ if(str[i]=='/') str[i]=' ';
43
+ }
44
+ stringstream s(str);
45
+ string temp;
46
+ while(s>>temp){
47
+ if(temp==".")continue;
48
+ if(temp==".."){
49
+ if(!q.empty())q.pop_back();
50
+ continue;
51
+ }
52
+ q.push_back(temp);
53
+ }
54
+ if(q.empty()) cout<<"/";
55
+ else
56
+ {
57
+ for(unsigned int i=0;i<q.size();i++)
58
+ cout<<"/"<<q[i];
59
+ }
60
+ cout<<endl;*/
61
+
62
+ stack<string>q;
63
+ string temp;
64
+ if(str[str.size()-1]!='/') str+="/";
65
+ unsigned int i=1;
66
+ while(i<str.size())
67
+ {
68
+ unsigned int n=str.find('/',i);
69
+ if(n!=string::npos)
70
+ {
71
+ temp=str.substr(i,n-i);
72
+ if(temp.compare("..")==0)
73
+ {
74
+ if(q.size()!=0)
75
+ q.pop();
76
+ }
77
+ else if(temp.compare(".")==0)
78
+ {
79
+ }
80
+ else
81
+ {
82
+ q.push(temp);
83
+ }
84
+ i=n+1;
85
+ }
86
+ }
87
+ if(q.size()!=0){
88
+ for(unsigned int i=0;i<(q.size()-1);)
89
+ {
90
+ ans=q.top()+ans;
91
+ ans='/'+ans;
92
+ q.pop();
93
+ }
94
+ ans=q.top()+ans;
95
+ q.pop();
96
+ }
97
+ ans='/'+ans;
98
+ cout<<ans<<endl;
99
+ return ;
100
+ }
101
+
102
+ int main()
103
+ {
104
+ cin>>p>>a;
105
+ cin.get();
106
+ for(int i=0;i<p;i++)
107
+ {
108
+ string temp;
109
+ getline(cin,temp);
110
+ temp=standard(temp);
111
+ check(temp);
112
+ }
113
+ return 0;
114
+ }
115
+ /*
116
+ 7
117
+ /d2/d3
118
+ /d2/d4/f1
119
+ /d4/f1
120
+ /d1/./f1
121
+ /d1///f1
122
+ /d1/
123
+ ///
124
+ /d1/../../d2
125
+ */
You can’t perform that action at this time.
0 commit comments