/*
* The largest and the same substring in two strings.
*
*
*
* Idea:
* 1. Since the obtained string is the largest substring, check whether the short string is in the long one.
* If so, the short string is the largest substring.
* 2. If not, use the short substring to decrement the substring length and determine whether the substring exists.
* If it already exists, you do not need to find it.
*/
Public class Test2 {
Public static void main (string [] ARGs ){
// The method stub automatically generated by todo
String S1 = "qwerabcdtyuiop ";
String S2 = "xcabcdvbn ";
String S = getmaxsubstring (S1, S2 );
System. Out. println ("s =" + S );
}
Private Static string getmaxsubstring (string S1, string S2 ){
// The method stub automatically generated by todo
String max = NULL, min = NULL;
Max = (s1.length ()> s2.length ())? S1: S2;
Min = max. Equals (S1 )? S2: S1;
For (INT I = 0; I <min. Length (); I ++ ){
For (INT x = 0, y = min. Length ()-I; y! = Min. Length () + 1; X ++, y ++ ){
String sub = min. substring (x, y );
If (max. Contains (sub ))
Return sub;
}
}
Return NULL;
}
}
The largest and identical substring in two strings