题解 | #DNA序列#

DNA序列

https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a

import sys
string,num = input().rstrip(),int(input().rstrip())
list0 = []
for i in range(2,len(string)+1):
    for j in range(0,len(string)):
        try:
            if i < len(string)+1 and i-j == num:
                list0.append(string[j:i])
            i+=1         
        except:
            pass
#list1 = sorted(list0,key=lambda x:len(x))

list2=[]
for i in list0:
    if len(i) == num and i.count("C") > 0 and i.count("G") > 0:
        list2.append([i,(i.count("C")+ i.count("G"))/len(i)])
print(sorted(list2,key=lambda x:x[1],reverse=True)[0][0])

开始理解的是自字符串不包括本身,其实应该包括;

开始理解相同cg不分前后,其实是要分的,从左到右分出的第一个子字符串

全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 11:16
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务