Advertisement
zydhanlinnar11

Anton Bingung Dimana

May 24th, 2022
860
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Tested by zydhanlinnar11 on May 25, 2022
  2. #include <iostream>
  3. #include <cassert>
  4. #include <vector>
  5. #include <string>
  6. using namespace std;
  7. typedef vector<string> vs;
  8.  
  9. inline string formatPath(vs &arr) {
  10.     string path = arr.front();
  11.     for(int i=1; i<arr.size(); i++) path += "/" + arr[i];
  12.     return path;
  13. }
  14.  
  15. int main() {
  16.     ios_base::sync_with_stdio(false); cin.tie(NULL);
  17.     #ifdef ZYD_WSL
  18.         freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
  19.     #endif
  20.     int q, s;
  21.     string cmd;
  22.     vs arr = {"home", "anton"};
  23.     getline(cin, cmd);
  24.     q = stoi(cmd);
  25.     assert(1 <= q && q <= 30);
  26.     while(q--) {
  27.         getline(cin, cmd);
  28.         if(cmd.find("whereami") != string::npos)
  29.             cout<<(arr.empty() ? "i am nowhere" : formatPath(arr))<<"\n";
  30.         else if (cmd.find("goto") != string::npos) {
  31.             string x = cmd.substr(5);
  32.             for(char &i: x) assert(i != ' ');
  33.             arr.push_back(x);
  34.         }
  35.         else if(cmd.find("goback") == string::npos)cout<<"Query not found\n";
  36.         else if(!arr.empty()) arr.pop_back();
  37.         else  cout<<"cannot go back\n";
  38.     }
  39.     return 0;
  40. }
Advertisement
RAW Paste Data Copied
Advertisement