コード例 #1
0
def abs_to_relative_two(s):
    stack = Stack()
    index = 0
    len_f = len(s)
    while index < len_f:
        while index< len_f and s[index] != '.':
            stack.push(s[index])
            index += 1
        point_count = 0
        while index<len_f and s[index] == '.':
            index += 1
            point_count += 1
        if point_count == 2:
            stack.pop()
            while not stack.isEmpty() and stack.peer() != '/':
                stack.pop()

        index += 1
    return ''.join(stack.items) # print relative path