题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
import java.util.*; /** * @author kingxing */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String str = scanner.nextLine(); int length = scanner.nextInt(); if (str.length() < length) { System.out.println(""); } char[] chars = str.toCharArray(); String longest = ""; int large = 0; for (int i = 0; i <= str.length() - length; i++) { int gc = 0; for (int j = i; j < i + length; j++) { if (chars[j] == 'C' || chars[j] == 'G') { gc++; } } if(gc > large){ large = gc; longest = String.valueOf(chars, i, length); } } System.out.println(longest); } } }