CCF 201604-3
参考:详细讲解地址
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <sstream>
#include <deque>
#define MAXN 330
using namespace std;
vector<string> load;
int main(){
int p;
cin >> p;
string s;
cin >>s;
getchar();
while(p--){
string op;
getline(cin,op);
// getchar();
if(op=="") op=s;
else if(op[0]!='/') op=s+"/"+op;
for(int i=0;i<op.size();i++){
if(op[i]=='/') op[i]=' ';
}
stringstream ss(op);
// cout << op << endl;
string ts;
deque<string> S;
while(ss>>ts){
if(ts==".") continue;
else if(ts==".." && !S.empty()) {
S.pop_back();
}
else if (ts != "..") S.push_back(ts);
}
cout << '/';
while(!S.empty()){
cout << S.front();
S.pop_front();
if(!S.empty()) cout << '/';
}
cout << endl;
}
return 0;
}