这道题用栈特别方便
string simplifyPath(string path) {
stack<string>a_path;
path+='/';
for(int i=1;i<path.length();++i){
if(path[i]=='/')continue;
else if(path[i]=='.'&&path[i+1]=='.'&&path[i+2]=='/'){
if(!a_path.empty())a_path.pop();
}
else if(path[i]=='.'&&path[i+1]=='/')continue;
else{
string temp_path="/";
while(path[i]!='/'){
temp_path+=path[i];
++i;
}
a_path.push(temp_path);
}
}
string res_path="";
while(!a_path.empty()){
res_path=a_path.top()+res_path;
a_path.pop();
}
if(res_path.empty())res_path+='/';
return res_path;
}
```