题解 | #DNA序列#

DNA序列

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

import java.util.Scanner;

// 题目不难 关键理解GC-Ratio是什么东西!我做了36分钟,罪过
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        int n = in.nextInt();
        int ratio = 1;
        String ratioStr = "";
        
        for(int i=0; i<s.length() - n + 1; i++) {
            String sub = s.substring(i, i+n);
            if(sub.indexOf("C")>=0 && sub.indexOf("G")>=0) {
                String temp = sub.replace("C","").replace("G","");
                if(n - temp.length() > ratio) {
                    ratioStr = sub;
                    ratio = n - temp.length();
                }
            }
        }
        System.out.println(ratioStr);
    }
}

全部评论

相关推荐

昨天 12:17
已编辑
商丘师范学院 Java
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 17:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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