题解 | #公共子串计算#
公共子串计算
https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String a = "", b = ""; int out = 0; // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case a = in.nextLine(); b = in.nextLine(); } for (int starti = 0; starti < a.length(); starti++) { for (int endi = starti+1; endi <= a.length(); endi++) { if (b.contains(a.substring(starti, endi))) { int outi = endi - starti; if (out < outi) { out = outi; } } } } System.out.println(out); } }