import java.util.Scanner;
/**
* 识别有效DNA序列
* @author Green.Gee
* @date 2022/11/14 14:33
* @email green.gee.lu@gmail.com
*/
public class DNA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
//@todo 满足序列要求 DNA序列为 ACGT 的子串有: ACG , CG , CGT 等等,但是没有 AGT , CT 等等
String DNA = in.nextLine();
/// @todo 校验字符 为序列内
int n = Integer.valueOf(in.nextLine());
int len = DNA.length();
int minus = len - n;
int index = 0,max = 0;
for(int i = 0; i < minus; i++){
int gcCount = 0;
for(int j = i;j< i + n;j++){// + n
if(DNA.charAt(j) == 'G' || DNA.charAt(j) == 'C'){
gcCount++;
}
}
if(gcCount > max){
max = gcCount;
index = i;
if(gcCount == n){
System.out.println(DNA.substring(index,index + n));
return;
}
}
}
System.out.println(DNA.substring(index,index + n));
}
}
}
11-25
784
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-24
372
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)