This is a problem on Huawei oj.First, if we write code in java, Huawei oj has the following three rules to follow,Otherwise the compilation fails or the use case fails.The rules are as follows:

(1) There must be no package name;

(2) The main class name can only be main;

(3) Do not output information unrelated to the result.

Well, following the above rules,The code we wrote is as follows (this code is not optimal,Just used to record the writing rules of java code on Huawei oj):

import java.util.scanner;
public class main {
 public static void main (string [] args) {
  scanner sc=new scanner (system.in);
  main mainobj=new main ();
  int len ​​= mainobj.getcommonstrlength (sc.next (), sc.next ());
  system.out.println (len);
 int getcommonstrlength (string str1, string str2) {
   str1=str1.tolowercase ();
   str2=str2.tolowercase ();
   int len1=str1.length ();
   int len2=str2.length ();
   string min=null;
   string max=null;
   string target=null;
   min=len1<= len2?str1:str2;
   //outermost layer:the length of the min substring,Starting from maximum length
   for (int i=min.length ();i>= 1;i--) {
    //Iterate through the min substrings of length i, starting from 0
    for (int j=0;j<= min.length ()-i;j ++) {
     target=min.substring (j, j + i);
     //Iterate over the max substring of length i to determine whether it is the same as the target substring,Starting from 0
     for (int k=0;k<= max.length ()-i;k ++) {
      if (max.substring (k, k + i) .equals (target)) {
       return i;
   return 0;
  • Previous Next-generation Eclipse goes into the cloud
  • Next What exactly is this in JavaScript (1)