主要看//之间的内容:如果是仍是/,或者是.,则忽略;如果是..,则弹出;否则压入堆栈。最后根据堆栈的内容进行输出。

string simplifyPath(string const& path)
{
vector<string> dirs;
for (auto i = path.begin(); i != path.end();)
{
i++;
auto j = find(i, path.end(), '/');
auto dir = string(i, j);//注意用法 if (!dir.empty() && dir != ".")//当有连续的///时dir为空
{
if (dir == "..")
{
if (!dirs.empty())
dirs.pop_back();
}
else
dirs.push_back(dir);
}
i = j;
} stringstream out;
if (dirs.empty())
{
out << "/";
}
else
{
for (auto dir : dirs)
{
out << '/' << dir;
}
} return out.str();
}

最新文章

  1. mongodb数据库迁移
  2. canvas实现绘画
  3. angular的directive笔记
  4. [wordpress] 输出一个过滤器绑定的方法
  5. 添加“返回顶部”小图标按钮的JS(JavaScript)代码详解
  6. IIS服务器 远程发布(Web Deploy)配置 VS2010 开发环境 Windows Server 2008服务器系统
  7. “字符串替换” 和 “模板设置” (application/config.php)
  8. node.js的安装的配置
  9. SpringBoot的第一个例子
  10. Oracle debug
  11. 学习animejs
  12. Delphi 10.3.1来了
  13. spring模拟ioc
  14. FPGA学习笔记. 二分频和三分频
  15. Windows平台编译SQLite 3
  16. CodeForces 76A Gift - 最小生成树
  17. npm 下载node-zookeeper包
  18. JS之this那些事
  19. ruby require的使用
  20. 指定Python线程数目

热门文章

  1. BZOJ5217:[Lydsy2017省队十连测]航海舰队——题解
  2. BZOJ4651 &amp; 洛谷1173 &amp; UOJ220:[NOI2016]网格——题解(附debug数据)
  3. Python通过PhantomJS获取JS渲染后的网页源代码
  4. 总结:Bias(偏差),Error(误差),Variance(方差)及CV(交叉验证)
  5. ubuntu14.04安装GTX 1080 ti遇到黑屏问题
  6. UVA315:Network(求割点)
  7. Java的switch是否支持String作为参数,还支持哪些类型?
  8. jQuery图表插件Flot中文文档
  9. 【C++ STL】Deques
  10. 【C++对象模型】第五章 构造、解构、拷贝 语意学