题解 | #DNA序列#

DNA序列

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

#include <stdio.h>
#include <string.h>

int main() {
    char str[1000];
    while(~scanf("%s",str))
    {
        int n;
        scanf("%d",&n);
        int len = strlen(str);
        int count = 0;
        int max;
        int max_index;
        for(int i =0;i<len-n+1;i++)
        {
            for(int j=i;j<i+n;j++)
            {
                if(str[j] == 'C'||str[j]=='G')
                count++;
            }
            if(count > max)
            {
                max = count;
                max_index = i;
            }
            count = 0;

        }
        for(int i = max_index;i<n+max_index;i++)
        {
            printf("%c",str[i]);
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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