class Solution {
public:
string simplifyPath(string path) {
stringstream is(path);
vector<string> strs;
string res = "", tmp = "";
while(getline(is, tmp, '/')) {
cout << tmp << endl;
if(tmp == "" || tmp == ".")
continue;
else if(tmp == ".." && !strs.empty())
strs.pop_back();
else if(tmp != "..")
strs.push_back(tmp);
}
for(string str:strs)
res += "/" + str;
if(res.empty())
return "/";
return res;
}
};
C++ getline函数切割字符串
猜你喜欢
转载自blog.csdn.net/qq_28133013/article/details/104041407
今日推荐
周排行