题解 | #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)