Facebook
From Sweltering Leech, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 132
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void show(deque <char> g)
  4. {
  5.         if(g.size() ==0) return;
  6.     deque <char> :: iterator it;
  7.     for (it = g.begin(); it != g.end(); ++it)
  8.         cout<< *it;
  9. }
  10. void del(deque<char> &a){
  11.         if(a.size() == 0) return;
  12.         while(a.back() != '/'){
  13.                 a.pop_back();
  14.         }
  15.         a.pop_back();
  16. }
  17. int main(){
  18.         ios::sync_with_stdio(0);
  19.         cin.tie(0);
  20.         string s,cm;
  21.         deque<char> a;
  22.         int n,i,j,key;
  23.         cin>>n;
  24.         fflush(stdin);
  25.         while(n>0){
  26.                 cin>>cm;               
  27.                 //cout<<cm<<endl;
  28.                 //cout<<"i :"<<i<<endl;
  29.                 if(cm == "pwd") {//kiem tra lenh
  30.                         show(a);
  31.                         cout<<'/';
  32.                 }
  33.                 else {
  34.                         cin>>s;
  35.                         j=0;
  36.                         while(s[j] != '\0'){
  37.                                 if(s[j] == '.') {
  38.                                         del(a);
  39.                                         j+=2;
  40.                                         continue;
  41.                                 }
  42.                                 a.push_back(s[j]);
  43.                                 j+=1;
  44.                         }
  45.                 }
  46.                 n-=1;
  47.         }
  48. }