Title: Maximum Common substring
The maximum common substring length problem is:
What is the maximum length of all substrings in the two string that can be matched.
For example: "Abcdkkk" and "BAABCDADABC",
The longest common substring that can be found is "ABCD", so the maximum common substring length is 4.
The following procedure is solved by the matrix method, which is a relatively effective solution to the small scale of the string.
Please analyze the idea of the solution and complement the missing code in the whole line.
/The sixth question of Blue Bridge Cup Public classMain {Static intf (String s1, string s2) {Char[] C1 =S1.tochararray (); Char[] C2 =S2.tochararray (); int[] A =New int[C1.length + 1] [C2.length + 1]; intMax = 0; for(inti = 1; i < a.length; i++) { for(intj = 1; J < A[i].length; J + +) { if(C1[i-1] = = C2[j-1]) {A[i][j]=a[i-1][j-1]+1;//Fill in//This place focuses on diagonal two-dimensional arrays and then looks at the diagonal that's longer if(A[i][j] >max) Max=A[i][j]; } } } returnMax; } Public Static voidMain (string[] args) {intn = f ("Abcdekkk", "BAABCDADABCD"); SYSTEM.OUT.PRINTLN (n); }}
Eighth session Blue Bridge Cup B group Java Sixth question