参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s1 = scanner.next(); String s2 = scanner.next(); int n1 = s1.length(); int n2 = s2.length(); int[][] dp = new int[n1 + 1][n2 + 1]; for(int i = 1; i <= n1; i++) for(int j = 1; j <= n2; j++) if(s1.charAt(i - 1) == s2.charAt(j - 1)) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); System.out.print(dp[n1][n2]); } }
0.0分
5 人评分
C语言考试练习题_排列 (C语言代码)浏览:1373 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:573 |
淘淘的名单 (C语言代码)答案错误???浏览:623 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:509 |
WU-字符串比较 (C++代码)浏览:824 |
Wu-求圆的面积 (C++代码)浏览:1994 |
The 3n + 1 problem (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:841 |
C二级辅导-分段函数 (C语言代码)浏览:790 |