题解 | #DNA序列#
DNA序列
http://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String dna = sc.nextLine();
int l = sc.nextInt();
int gcMax = 0;
int gcMaxIndex = 0;
for (int i = 0; i < dna.length()-l; i++) {
int j = i;
int gcCount = 0;
while(j < i+l){
char c = dna.charAt(j);
if(c=='G' || c=='C'){
gcCount++;
}
j++;
}
if(gcCount > gcMax){
gcMax = gcCount;
gcMaxIndex = i;
}
}
for (int i = gcMaxIndex; i < gcMaxIndex+l; i++) {
System.out.printf(String.valueOf(dna.charAt(i)));
}
}
}