还可以,有一些细节
#include <bits/stdc++.h>
#define DIR 1
#define FE 2
using namespace std;
vector<string> initPath;
int n;
string pa;
void init() {
cin >> pa;
getchar();
stringstream ss(pa);
string tmp;
while (getline(ss, tmp, '/')) {
if (!tmp.empty()) initPath.push_back(tmp);
}
}
void begWithRoot(vector<string>& con, bool flg) {
vector<string> st;
if (flg) st = initPath;
string ret;
for (int i = 0; i < con.size(); i++) {
if (con[i] == ".") continue;
else if (con[i] == "..") {
if (st.size()) st.pop_back();
} else {
st.push_back(con[i]);
}
}
for (auto& c : st) {
ret += "/";
ret += c;
}
cout << ret << '\n';
}
void solve() {
string s;
char c;
while ((c = getchar()) != '\n') s.push_back(c);
if (s.empty()) {
cout << pa << '\n';
return;
}
vector<string> con;
string tmp;
stringstream ss(s);
while (getline(ss, tmp, '/')) {
if (!tmp.empty()) {
con.push_back(tmp);
}
}
if (con.empty()) {
cout << "/\n";
return;
}
int flg = s[0] == '/' ? 0 : 1;
begWithRoot(con, flg);
}
int main() {
cin >> n;
getchar();
init();
for (int i = 1; i <= n; i++) {
solve();
}
}