题解 | #DNA序列#

DNA序列

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        int n=in.nextInt();
        int len=s.length();
        double max=0;
        String res="";
        for(int i=0;i<=len-n;i++){
            double count=count(s.substring(i,i+n));
            if(count>max){
                max=count;
                res=s.substring(i,i+n);
            }
        }
        System.out.println(res);
    }
    public static double count(String s){
        char[] arr=s.toCharArray();
        int len=s.length();
        int CG=0;
        for(int i=0;i<len;i++){
            if(arr[i]=='G'||arr[i]=='C'){
                CG++;
            }
        }
        return (double)CG/len;
    }
}

全部评论

相关推荐

06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
一tiao酸菜鱼:秋招还没正式开始呢,就准备有结果了。。。。?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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