题解 | #DNA序列#
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
while True: try: str0 = input() n = int(input()) x = str0.count('A') + str0.count('C') + str0.count('G') + str0.count('T') if 1 <= len(str0) <= 1000 and 0 < n <= len(str0) and str0.isupper() and x == len(str0): arr0 = list(str0) dic = {} for i in range(len(arr0)-n+1): str1 = '' for x in range(i, i + n): str1 += arr0[x] sm=str1.count('C')*0.5+str1.count('G')*0.5 if sm not in dic.keys(): dic[sm]=str1+',' else: dic[sm]=dic[sm]+str1+',' arr1=[] for x in dic.keys(): arr1.append(x) arr1.sort(reverse=True) print(dic[arr1[0]].split(',')[0]) else: continue break except: break