题解 | #DNA序列#

DNA序列

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

l = list(input())
n = int(input())
max_len, tmp_len = 0, 0
max_s, tmp_s = "", []
result=""
for i in range(n):
    if l[i] == "C" or l[i] == "G":
        max_len += 1
        tmp_len += 1
    max_s+=l[i]
    tmp_s.append(l[i])
for i in range(1, len(l)):
    if l[i - 1] == "C" or l[i - 1] == "G":
        before = 1
    else:
        before = 0
    try:
        after_word = l[i + n - 1]
        if l[i + n - 1] == "C" or l[i + n - 1] == "G":
            after = 1
        else:
            after = 0
    except:
        break
    tmp_len = tmp_len - before + after
    tmp_s.pop(0)
    tmp_s.append(after_word)
    if tmp_len > max_len:
        max_len = tmp_len
        max_s = "".join(tmp_s)

print(max_s)

全部评论

相关推荐

11-09 01:22
已编辑
东南大学 Java
高级特工穿山甲:羡慕,我秋招有家企业在茶馆组织线下面试,约我过去“喝茶详谈”😢结果我去了发现原来是人家喝茶我看着
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务