华为OD机试
OD机试
前两题忘了,很简单,但是ac都只有90
第三题ac 25,能想到的用例都能通过,可能是我没有读懂题
有没有大佬来指正一下
输入ABV 连续字符串满足 在A和B中的位置相同并且连续 连续字符串的ASCLL绝对值之和|A[i]-B[i]|之和小于等于V 输出最长的连续字符串数量 (略其它无关的限制条件) # 示例输入 # xxabcdef # aacdefgh # 5 # 输出 # 2 # 说明:ab->cd,bc->de,cd->ef,...最长的为2 A = input() B = input() V = int(input()) assert 1 <= len(A) == len(B) <= 1000 and A.islower() and B.islower() pd_1 = [0 for _ in A] pd_2 = [0 for _ in A] pd_3 = [abs(ord(A[i]) - ord(B[i])) for i in range(len(A))] for i, v in enumerate(A[:-1]): if chr(ord(v) + 1) == A[i + 1] and chr(ord(B[i]) + 1) == B[i + 1]: if pd_1[i] == 0: pd_1[i] = 1 pd_1[i + 1] = pd_1[i] + 1 for i, v in enumerate(pd_1): if v != 0: if i == 0: pd_2[i] = pd_3[i] elif v == pd_1[i - 1] + 1: pd_2[i] = pd_3[i] + pd_2[i - 1] elif v != 0: pd_2[i] = pd_3[i] max_len = 0 for i, v in enumerate(pd_1): if v == 0: continue if pd_2[i] <= V: max_len = max(max_len, v) if max_len == 0: min_abs = min(pd_3) max_len = 1 if min_abs <= V else 0 print(max_len)#Python##华为笔试##华为od#