题解 | #DNA序列#

DNA序列

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

屎堆写法

import java.lang.*;
public class Main{
     public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
         String in = sc.nextLine();
         int n = sc.nextInt();//子串
        
         List<String> list = new ArrayList<String>();
         list =  getAllChild(in,n);
         float maxrat = 0;
         int maxindex = 0;
         boolean first = true;
         for(int i=0;i<list.size();i++){
             if(first){
                 maxrat = gcRatio(list.get(i),n);
                 maxindex = i;
                 first = false;
             }else{
                 if(gcRatio(list.get(i),n)>maxrat){
                     maxrat = gcRatio(list.get(i),n);
                     maxindex = i;
                 }
             }
         }
         System.out.println(list.get(maxindex));
      }
    public static List<String> getAllChild(String in,int len){
        List<String> list = new ArrayList<String>();
        for(int i = 0;i<in.length()-len+1;i++){
            list.add(in.substring(i,i+len));
        }
        return list;
    }
    public static float gcRatio(String str,int len){
        int count = 0;
        for(int i =0;i<str.length();i++){
            if(str.charAt(i)=='C'||str.charAt(i)=='G')
                count++;
        }
        
        float rat = (float)count/(float)len;
        return rat;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务