字节跳动笔试第四题,回溯
字节跳动第四题,回溯
num = list(input().strip()) lyst = [i for i in range(1,27)] alpha = [i for i in range(65, 91)] dyct = {str(lyst[i]): chr(alpha[i]) for i in range(len(lyst))} def bt(num, tmp): if not num: res.append([tmp]) return if int(num[:1]) > 0: bt(num[1:], tmp+dyct[num[:1]]) if len(num) > 1 and num[:2] in dyct: bt(num[2:], tmp+dyct[num[:2]]) res = [] bt(''.join(num), '') res.sort() for i in res: print(i[0])#笔试题目##字节跳动#