import java.util.Scanner;
public class CodeCut {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
StringBuffer sb = new StringBuffer(str);
String str1 = sb.reverse().toString();
String result = fun(str,str1);
System.out.println(result.length());
}
private static String fun(String str, String str1) {
str = str.toLowerCase();
str1 = str1.toLowerCase();
for (int i = 0; i < str1.length(); i++) {
for (int j = 0,k = str1.length()-i; k != str1.length() + 1; j++,k++) {
String temp = str1.substring(j, k);
if(str.contains(temp))
return temp;
}
}
return null;
}
}
注意:该题和之前求两个字符串的最大公共字符串的长度是一样的。
【中级】字符串运用-密码截取
最新推荐文章于 2024-04-23 15:11:40 发布