Untitled
user_5668965
c_cpp
a year ago
938 B
14
Indexable
#include <bits/stdc++.h>
#define ll long long
#define db(x) cout << (#x) << " = " << x << "\n" ;
#define pb push_back
#define mt make_tuple
#define fr first
#define sc second
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector <string> s;
ll n;
cin >> n;
for(ll i = 0;i<n;i++){
string t;
cin >> t;
if(t=="pwd"){
cout << "/";
for(auto x : s){
cout << x << "/";
}
cout << endl;
} else {
string a;
cin >> a;
string o;
if(a[0]=='/') s.clear();
for(ll i = 0;i<a.size();i++){
if(a[i]=='/'){
if(o==".."){
s.pop_back();
} else if(o.size()) s.pb(o);
o.clear();
} else o.pb(a[i]);
}
if(o==".."){
s.pop_back();
} else if(o.size()) s.pb(o);
}
}
return 0;
} Editor is loading...
Leave a Comment