题解 | #DNA序列#

DNA序列

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        String zfc = fzhinput.nextLine();
        int cd = fzhinput.nextInt();
        int num = 0;
        float max = 0;
        float zf[] = new float[zfc.length() - cd+1];
        StringBuilder stack = new StringBuilder();
        for (int i = 0; i <= zfc.length() - cd; i++) {
            num = 0;
            for (int j = i; j < i + cd; j++) {
                if (zfc.charAt(j) == 'C' || zfc.charAt(j) == 'G') {
                    num++;
                }
            }
            
            zf[i] = (float)num / (float)cd;
            max = Math.max(max, zf[i]);
        }
        for (int i = 0; i <= zfc.length() - cd; i++) {
            if ( zf[i] == max) {
                for (int j = i; j < i + cd; j++) {
                    stack.append(zfc.charAt(j));
                }
                break;
            }
        }
        System.out.println(stack.toString());
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-27 10:48
点赞 评论 收藏
分享
一名愚蠢的人类:多少games小鬼留下了羡慕的泪水
投递荣耀等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务