题解 | #DNA序列# 循环遍历子序列,找出最大GC-Ratio输出对应基因
DNA序列
http://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
try:
DNA = input() # 记录DNA
k = int(input()) # 记录序列长度
l = len(DNA) # 记录DNA长度
DNA_little = '' # 保存用于遍历的序列
Max_DNA = '' # 保存GC-Ratio最高的序列
Max_ratio = 0 # 保存GC-Ratio
for i in range(l-k+1):
DNA_little = DNA[i:i+k] # 遍历子序列
m = DNA_little.count('G')
n = DNA_little.count('C')
ratio = m + n # 计算GC-Ratio
if ratio > Max_ratio:
Max_ratio = ratio # 存储最大GC-Ratio
Max_DNA = DNA_little # 存储最大GC-Ratio对应的基因子序列
print(Max_DNA)
except:
break