1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
自行实现
public class HJ063 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(getDnaBeginner(sc.nextLine(), Integer.parseInt(sc.nextLine())));
}
public static String getDnaBeginner(String dna, int n) {
int maxCount = 0;
int index = 0;
for (int i = 0; i < dna.length() -(n-1); i++) {
int curCnt = count(dna.substring(i, i + n));
if (curCnt > maxCount) {
maxCount = curCnt;
index = i;
}
}
return dna.substring(index, index + n);
}
public static int count(String str) {
int cnt = 0;
for (char c : str.toCharArray()) {
if (c == 'C' || c == 'G') {
cnt++;
}
}
return cnt;
}
}