题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
不是忘了写(double)就是忘了赋值replacement为“”,考试的话已经挂了吧。。。 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str; while((str = br.readLine()) != null) { double gcRatio = 0.0; String childMax = ""; int n = Integer.parseInt(br.readLine()); for (int i = 0; i <= str.length()-n; i++) { String child= str.substring(i, n+i); String nogcChild = child.replaceAll("G", "").replaceAll("C", ""); double gcRatioTemp = (double)(child.length() - nogcChild.length())/child.length(); if(gcRatioTemp > gcRatio) { gcRatio = gcRatioTemp; childMax = child; } } System.out.println(childMax); } } }