题解 | DNA序列
while True:
try:
str,n = input(),int(input())
dic = {} # 创建字典,记录每个子串中C或G出现次数
for i in range(len(str)):
if i+n <=len(str): # 保证每个子串长度都是n,且不会超过字符串序列
s = str[i:i+n]
dic[s] = s.count('C') + s.count('G')
else:
break
ls = sorted([v for v in dic.values()]) # 创建列表,提取次数,排序
for k,v in dic.items():
if v == ls[-1]: # 找到最大次数第一次出现对应的子串
print(k)
break
except:
break
