//刚开始写只有90分 后来看了别人的题解后发现有一种情况是所给当前路径为空..........然后...需要在给相对路径加入时多个.size == 0 和.size!=0 的条件....不然不会有结果. 然后感觉为绝对路径时...也应该加个条件吧 我没加...
#include<iostream>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<vector>
using namespace std;
vector<string> st1, st2;
void InStack(string s) {
string flag="/";
int position=0;
while((position=s.find(flag,position))!=string::npos) {
s.replace(position, 1, " ");
position++;
}
// cout << s << endl;
stringstream ss(s);
while(ss >> s) {
if(s == "..") {
if(st2.size())
st2.pop_back();
} else if(s == ".") {
;
} else st2.push_back(s);
}
if(st2.size() == 0){
}
}
void InStack1(string s) {
string flag="/";
int position=0;
while((position=s.find(flag,position))!=string::npos) {
s.replace(position, 1, " ");
position++;
}
// cout << s << endl;
stringstream ss(s);
while(ss >> s) {
if(s == "..") {
if(st1.size())
st1.pop_back();
} else if(s == ".") {
;
} else st1.push_back(s);
}
for(int i=0; i<st1.size(); i++) {
cout << "/" << st1[i];
}
if(st1.size() == 0) {
cout << "/";
}
cout << endl;
}
void InStack2(string s) {
string flag="/";
int position=0;
while((position=s.find(flag,position))!=string::npos) {
s.replace(position, 1, " ");
position++;
}
stringstream ss(s);
while(ss >> s) {
if(s == "..") {
if(st2.size())
st2.pop_back();
} else if(s == ".") {
continue;
} else {
if(st2.size() && st2.back() == s)//...有种情况是st2.size == 0...
continue;
st2.push_back(s);
}
}
for(int i=0; i<st2.size(); i++) {
cout << "/" << st2[i];
}
if(st2.size() == 0) {
cout << "/";
}
cout << endl;
}
int main() {
int n;
string cur, s;
cin >> n;
cin.get();
getline(cin, cur);//绝对路径
for(int i=0; i<n; i++) {
while(!st1.empty()) {
st1.pop_back();
}
while(!st2.empty()) {
st2.pop_back();
}
getline(cin, s);
if(s[0] == '/')//绝对路径
InStack1(s);
else {//相对路径
InStack(cur);
InStack2(s);
}
}
return 0;
}