华为机试二星题--解密犯罪时间
我的想法先从分钟起加时间,如果能凑成就输出
如果凑成的数字小于原始分钟,说明时针+1
如果除了原始分钟凑不出任何一对,就凑时针
算法不用 没用回溯 用了字典 python3实现
n, m = input().split(':') s = n + m d = set(s) def search(l): d1 = set(l) if d1 <= d: return True else: return False mn = 0 nn=int(n) shi = [i for i in range(1, 25)] fen = [i for i in range(1, 61)] fenn = fen[int(m):] + fen[:int(m)-1] for each in fenn: if search(str(each)): mn = each break if mn<int(m): nn=int(n)+1 shin = shi[int(nn):] + shi[:int(nn)] if not mn: for each in shin: if search(str(each)): nn = each mn = m break if mn<10: mn='0'+str(mn) if nn<10: nn='0'+str(nn) print(':'.join([str(nn), str(mn)]))