8月7日笔试, 网易互娱的算法工程师, 第一题身份证问题,感觉代码逻辑是对的,但是通过0%,代码如下,求问各位大佬,错误在哪儿?
import copy N = list(map(int, input())) numbs = [] def findNum(numb_list): num1_14 = list(map(int, numb_list[0:14])) num15_17 = numb_list[14:17] num18 = numb_list[-1] avail_list = [] n18_dict = {0:'1', 1:'0', 2:'X', 3:'9', 4:'8', 5:'7', 6:'6', 7:'5', 8:'4', 9:'3', 10:'2'} xishu = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] for i in range(10): for j in range(10): for k in range(10): sum1_17 = 0 num1_17 = copy.deepcopy(num1_14) if num15_17[0] == '*': num15 = i else: num15 = int(num15_17[0]) if num15_17[1] == '*': num16 = j else: num16 = int(num15_17[1]) if num15_17[2] == '*': num17 = k else: num17 = int(num15_17[2]) num1_17.extend([num15, num16, num17]) for a,b in zip(num1_17, xishu): sum1_17 += a*b # sum1_17 = map(lambda (a,b):a*b, zip(num1_17, xishu)) n18 = sum1_17 % 11 rnum18 = n18_dict[n18] # import pdb; pdb.set_trace() if numb_list[-1] == rnum18: if [num15, num16, num17] not in avail_list: # print(i, j, k) avail_list.append([num15, num16, num17]) return avail_list for _ in range(N[0]): numb_list = list(map(str, input())) avail_list = findNum(numb_list) # print(avail_list) print(len(avail_list))
全部评论
(4) 回帖