题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
s = input() n = int(input()) GC_Ratio = 0 res = [] for i in range(len(s)-n+1): tmp = (s[i:i+n].count('G') + s[i:i+n].count('C')) / n if tmp == 1: print(s[i:i+n]) break elif tmp > GC_Ratio: res.append(s[i:i+n]) GC_Ratio = tmp else: print(res[len(res)-1])
加了一个GC_Ratio是否为1 的判断,当GC_Ratio为1时,必定是值最大且是第一个,直接结束循环返回即可。