Eighth session Blue Bridge Cup B group Java Sixth question

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.