题解 | #DNA序列#

DNA序列

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

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


int main(){

    char str[1002];
    scanf("%s", str);

    int n;
    scanf("%d", &n);

    int len = strlen(str);
    char tmp[n], tmp_max[n];
    float max = 0;

    for(int i = 0; i < len - n + 1; i++){
        sprintf(tmp, "%.*s", n, str + i);
        int count = 0;
        for(int j = 0; j < n; j++){
            if(tmp[j] == 'C' || tmp[j] == 'G'){
                count++;
            }
        }
        if(max < (float)count / n){
            max = (float)count / n;
            sprintf(tmp_max, "%s", tmp);
        }

    }

    printf("%s", tmp_max);
    return 0;
}

全部评论
sprintf(tmp, "%.*s", n, str + i); //从str + i 开始复制 n 个字符到 tmp
点赞 回复 分享
发布于 2023-03-13 14:55 陕西

相关推荐

湫湫湫不会java:1.在校经历全删了2.。这些荣誉其实也没啥用只能说,要的是好的开发者不是好好学生3.项目五六点就行了,一个亮点一俩行,xxx技术解决,xxx问题带来xxx提升。第一页学历不行,然后啥有价值的信息也没有,到第二页看到项目了,第一个项目九点,第二个项目像凑数的俩点。总体给人又臭又长,一起加油吧兄弟
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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