一、题目
二、代码
package niuke;
import java.util.Scanner;
public class Test10 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String str = in.nextLine();
int n = in.nextInt();
int max = 0,begin = 0;
for (int i = 0; i < str.length()-n; i++) {
int count = 0;
for (int j = i; j < i+n; j++) {
String s = String.valueOf(str.charAt(j));
if ("G".equals(s) || "C".equals(s)) {
count++;
}
}
if (count > max) {
max = count;
begin = i;
}
}
System.out.println(str.substring(begin,begin+n));
}
}
}
|