python-APCS-2022/10/23實作第三題:石窟探險-sol2 === ### ZeroJudge:j124石窟探險 ### 解法2 ### [解法1在這裡](https://hackmd.io/@Aji-Hsu/SyMNcQchs) --- <font color="#FFEE99">**完整程式碼**</font> --- ```python= nums = [int(i)for i in input().split()] nodes = [nums[0]] nodesLimit = [nums[0] % 2 + 2] total = 0 for i in nums[1:]: if i != 0: total += abs(i - nodes[-1]) nodesLimit[-1] -= 1 if nodesLimit[-1] == 0: nodesLimit.pop() nodes.pop() nodes.append(i) nodesLimit.append(i % 2 + 2) else: nodesLimit[-1] -= 1 if nodesLimit[-1] == 0: nodesLimit.pop() nodes.pop() print(total) ``` ###### tags: `APCS` ###### tags: `python`