华为机试-DNA序列(HJ63)——纯C

DNA序列

https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a?tpId=37&&tqId=21286&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking

纯C

#include <stdlib.h>
#include <stdio.h>

int main()
{
    char *str = (char *)malloc(sizeof(char )*500);
    while(gets(str))
    {
        int n;
        scanf("%d", &n);
        char *pstr = str;
        int count, max=0;
        for(int i=0; i<strlen(str); i++)
        {
            count=0;
            for(int j=i; j<(i+n); j++)
            {
                if(str[j] == 'G' || str[j] == 'C')
                {
                    count++;
                    if(count > max)
                    {
                        max=count;
                        pstr = str+i;
                    }
                }
            }
        }
        for(int i=0; i<n; i++)
        {
            printf("%c", *(pstr+i));
        }
        printf("\n");
    }
    free(str);
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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