题解 | #DNA序列#

DNA序列

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            int len = in.nextInt();
            char[] c = new char[str.length()];
            for (int i = 0; i < str.length(); i++) {
                c[i] = str.charAt(i);
            }
            int index = -1;
            double max = -1;
            for (int i = 0; i <= str.length() - len; i++) {
                int count = 0;
                for (int j = 0; j < len; j++) {
                    if (c[i + j] == 'C' || c[i + j] == 'G') {
                        count ++;
                    }
                }
                double rare = (double) count / str.length();
                if (i >= 0 && rare > max) {
                    index = i;
                    max = rare;
                }
            }
            if (index != -1) {
                System.out.println(str.substring(index, index + len));
            }
            System.out.println("");
        }
    }
}

全部评论

相关推荐

不是哥们,我投的开发岗啊,也不至于直接调剂销售岗吧
哞客37422655...:先面一面探探口风,真要转销售就得把提成问清楚;说不定还能内部跳回技术,别直接拒。
我的工作日记
点赞 评论 收藏
分享
2025-11-24 14:22
安徽师范大学 财务
勇敢求职牛牛:然后简历的话,我个人意见(双非本有零星的垃圾offer),学校经历太多了,写了也应该往财务方面靠,然后技能方面多写一点吧,比如ERP的水平,对某些行业的流程(制造业),对数据的逻辑和敏感之类的
点赞 评论 收藏
分享
2025-12-15 11:27
门头沟学院 Java
哇哇的菜鸡oc:所有人不要理会,就好了,后面他就知道怎么回事了,只能说有的时候市场都是被宰的人搞坏的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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