华为OD机试 - 攀登者1(Java & JS & Python & C & C++)
后台-插件-广告管理-内容页头部广告(手机) |
weixin_43354145: [code=python] def dfs(nums: list, result: list, path: list): if len(path) == 4: hour = "".join(path[0:0 + 2]) mintue = "".join(path[2:2 + 2]) if 0 <= int(hour) <= 23 and 0 <= int(mintue) <= 59 and (hour, mintue) not in result: result.append((hour, mintue)) return for i in range(0, len(nums)): path.append(nums[i]) dfs(nums, result, path) path.pop() def getresult(): line = input() target = (line.split(":")[0], line.split(":")[1]) digits = [_ for _ in line if _.isdigit()] res = [] dfs(digits, res, []) res.sort(key=lambda x: (x[0], x[1])) # print(res) l = len(res) - 1 for i, r in enumerate(res): if r == target: if i != l: return res[i + 1][0] + ":" + res[i + 1][1] else: return res[0][0] + ":" + res[0][1] if __name__ == "__main__": print(getresult()) [/code]
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。
在线投稿:投稿 站长QQ:1888636
后台-插件-广告管理-内容页尾部广告(手机) |