Facebook
From Soft Parakeet, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 146
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void showstack(stack <int> s)
  4. {
  5.     while (!s.empty())
  6.     {
  7.         cout << '\t' << s.top();
  8.         s.pop();
  9.     }
  10. }
  11. void del(stack<int> &a){
  12.         if(a.size() == 0) return;
  13.         while(a.top() != '/'){
  14.                 a.pop();
  15.         }
  16.         a.pop();
  17. }
  18. int main(){
  19.         ios::sync_with_stdio(0);
  20.         cin.tie(0);
  21.         string s;
  22.         stack<int> a;
  23.         int n,i,j,key;
  24.         cin>>n;
  25.         while(n>0){
  26.                 cin>>s;
  27.                 i=0;
  28.                 char cm[5];
  29.                 while(s[i]!=' ' && s[i]!='\0'){//cp phan command
  30.                         cm[i]=s[i];
  31.                         i+=1;  
  32.                 }
  33.                 cm[i]='\0';
  34.                 if(strcmp(cm,"pwd") == 0) {//kiem tra lenh
  35.                         showstack(a);
  36.                         cout<<'/';
  37.                         cout<<'\n';
  38.                 }
  39.                 else{
  40.                         j=i+1;
  41.                         while(s[j] != '\0'){
  42.                                 if(s[j] == '.') {
  43.                                         del(a);
  44.                                         j+=2;//nhay den vi tri dia chi
  45.                                         continue;
  46.                                 }
  47.                                 a.push(s[j]);
  48.                                 j+=1;
  49.                         }
  50.                 }
  51.                 n-=1;
  52.         }
  53. }