题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a?tpId=37&tqId=21286&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=undefined&tags=&title=
- 这代码里还是很多坑的
s = input() n = int(input()) idx, cnt, max_cnt = 0, 0, 0 for i, ch in enumerate(s): if i >= n and (s[i-n] == 'C' or s[i-n] == 'G'): cnt -= 1 if ch == 'G' or ch == 'C': cnt += 1 # 确保字串长度等于n if i >= n - 1 and max_cnt < cnt: idx = i max_cnt = cnt print(s[(idx - n + 1):idx+1])