标签:
import java.util.Arrays; import java.util.Scanner; public class GetCommonString { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str1 = scan.next().toLowerCase(); String str2 = scan.next().toLowerCase(); if(str1.length() < str2.length()) getLen(str1,str2); else getLen(str2, str1); } private static void getLen(String str1, String str2) { int [] a = new int[str2.length()]; Arrays.fill(a, 0); for (int i = 0; i < str2.length(); i++) { for (int j = 0; j < str1.length(); j++) { if(str2.charAt(i)==str1.charAt(j)) a[i]=1; } } StringBuffer sb = new StringBuffer(); for (int i = 0; i < a.length; i++) { sb.append(a[i]); } String s = sb.toString(); String[] result = s.split("0"); int max = 0; for (int i = 0; i < result.length; i++) { if(result[i].length() > max) max = result[i].length(); } System.out.println(max); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/liaction/article/details/47761629