学习 | #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 scanner = new Scanner(System.in);
        scanner.useDelimiter("\n");
        while (scanner.hasNext()) {
            String S = scanner.next();
            int N = scanner.nextInt();
            int max = N;
            boolean A= false;
            while (max>0) {
                int left = 0;
                int right = N+left-1;
                while (right<S.length()) {
                    String substring = S.substring(left, right + 1);
                    if (substring.length() - substring.replaceAll("[G_C]", "").length() == max) {
                        System.out.println(substring);
                        A = true;
                        break;
                    }
                    left++;
                    right++;
                }
                if (A) {
                   break; 
                }
                max--;
            }
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务