Given an absolute path for a file (Unix-style), simplify it.

For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c" Corner Cases:
Did you consider the case where path = "/../"?
In this case, you should return "/".
Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
In this case, you should ignore redundant slashes and return "/home/foo".

  

class Solution {
public:
string simplifyPath(string path) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<string> tp;
string res;
int len = path.size();
if(len < ) return string("/");
const char * str = path.c_str();
char buffer[];
int pos = ,num;
do{
buffer[] = '\0';
num = sscanf(str + pos,"/%[^/]/",buffer);
int size = strlen(buffer);
if(size == && num == )// case ://
pos++;
else if( size == ){ //case :/./
if(buffer[] != '.')
{
tp.push_back(string(buffer));
}
pos+= ;
}else if(size == && buffer[] =='.' && buffer[] == '.'){//case : /../
if(!tp.empty())
tp.pop_back();
pos+= ;
}else if(size > ){ //case :normal tp.push_back(string(buffer));
pos = pos + + size;
} }while(- != num && pos <len ); len = tp.size(); if(len < )
res+= '/';
for(int i = ; i< len ; i++)
{
res+='/';
res+=tp[i];
} return res;
}
};

LeetCode_Simplify Path的更多相关文章

  1. NodeJs之Path

    Path模块 NodeJs提供的Path模块,使得我们可以对文件路径进行简单的操作. API var path = require('path'); var path_str = '\\Users\\ ...

  2. 【原】实时渲染中常用的几种Rendering Path

    [原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...

  3. Node.js:path、url、querystring模块

    Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...

  4. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  5. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  6. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  7. Thinking in Unity3D:渲染管线中的Rendering Path

      关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...

  8. node之path模块

    node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...

  9. Linux系统修改PATH环境变量方法

    在Linux安装一些软件通常要添加路径环境变量PATH.PATH环境变量通俗的讲就是把程序的路径"备案"到系统中,这样执行这些程序时就不需要输入完整路径,直接在bash输入程序名就 ...

随机推荐

  1. Unity中的关节

    关节组件一共分为5大类,它们分别是链条关节.固定关节.弹簧关节.角色关节和可配置关节.链条关节(Hinge Joint):将两个物体以链条的形式绑在一起,当力量过大超过链条的固定力矩时,两个物体就会产 ...

  2. PSAM 卡的应用操作方法

    PSAM 卡的应用        PSAM 功能 终端安全存储模块        PASM  常用于 脱机交易的 安全认证        脱机交易的流程          1.卡片对持卡人的认证(防止 ...

  3. Powershell 定义文本

    使用引号可以定义字符串,如果想让自己定义的字符串原样输出,可以使用单引号. 1 2 $text='$fei $(tai) $env:windir 飞苔博客 (20+2012)' $text 输出: $ ...

  4. Java7新语法 -try-with-resources

    http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html The try-with- ...

  5. 【转】Math.Atan2 方法

    原文网址:https://msdn.microsoft.com/zh-cn/library/system.math.atan2.aspx 返回正切值为两个指定数字的商的角度. 命名空间:  Syste ...

  6. 好用的QT连接

    QT属性控件项目https://github.com/lexxmark/QtnProperty比特币交易软件https://github.com/JulyIGHOR/QtBitcoinTrader导航 ...

  7. 第28讲 UI组件之 ListView和ArrayAdapter

    第28讲 UI组件之 ListView和ArrayAdapter 1. Adapter 适配器 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的 ...

  8. Javascript:作用域 学习总结

    作用域(scope): 变量与函数的可访问范围,控制着变量与函数的可见性和生命周期   作用域分类: javascript中,变量的作用域分为:全局作用域,局部作用域 局部变量的优先级大于全局变量,或 ...

  9. [RxJS] Adding Conditional Logic with Filter

    Often you only want values to proceed through your stream if they meet certain criteria, just as if ...

  10. 浅谈管道模型(Pipeline)

    本篇和大家谈谈一种通用的设计与处理模型--Pipeline(管道). Pipeline简单介绍 Pipeline模型最早被使用在Unix操作系统中.据称,假设说Unix是计算机文明中最伟大的发明,那么 ...