题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String str = sc.nextLine();
String nn = sc.nextLine();
int n = Integer.parseInt(nn);
List<String> alist = new ArrayList<>();
for (int j = 0; j < str.length(); j++) {//abcde
for (int k = str.length(); k > j; k--) {
alist.add(str.substring(j,k));
}
}
List<String> list = new ArrayList<>();
for (String temp:alist
) {
if (temp.length()==n){
list.add(temp);
}
}
double temp = 0.0;
int index = 0;
for (int j = 0; j < list.size(); j++) {
String str1 = list.get(j);
double Glen = str1.length()-str1.replaceAll("G","").length();
double Clen = str1.length()-str1.replaceAll("C","").length();
double GC = (Glen + Clen)/str1.length();
if (GC>temp){
temp = GC;
index = j;
}
}
System.out.println(list.get(index));
}
}
}


