-
Notifications
You must be signed in to change notification settings - Fork 15
/
158-C.cpp
41 lines (34 loc) · 876 Bytes
/
158-C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
ad-hoc > implementation
difficulty: easy
date: 09/Mar/2020
by: @brpapa
*/
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N; cin >> N;
vector<string> currAbsPath;
while (N--) {
string cmd; cin >> cmd;
if (cmd == "pwd") {
cout << "/";
for (string dir : currAbsPath) cout << dir << "/";
cout << endl;
}
else if (cmd == "cd") {
string query; cin >> query;
int l = 0;
if (query[0] == '/') currAbsPath.clear(), l++;
for (int r = l+1; r <= query.size(); r++)
if (query[r] == '/' || r == query.size()) {
string dir = query.substr(l, r-l);
if (dir == "..") currAbsPath.pop_back();
else currAbsPath.push_back(dir);
l = r+1;
}
}
}
return 0;
}