题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String sequence = sc.nextLine(); int n = Integer.parseInt(sc.nextLine()); List<String> gcList = new ArrayList<>(); int start = 0; int end = n; while (end <= sequence.length()) { String gc = sequence.substring(start, end); gcList.add(gc); start ++; end ++; } int max = Integer.MIN_VALUE; String gcRatio = ""; for (String gc : gcList) { int len = gc.replace("A", "").replace("T", "").length(); if (len > max) { max = len; gcRatio = gc; } } System.out.println(gcRatio); } } }