Guest User

Untitled

a guest
Mar 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Solution {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int T = sc.nextInt();
  7. for (int t = 1; t <= T; t++) {
  8. String a = sc.next();
  9. String b = sc.next();
  10. int[][]lcs=new int[a.length()+1][b.length()+1];
  11. for(int z=1;z<=a.length();z++) {
  12. for(int y=1;y<=b.length();y++) {
  13. if(a.charAt(z-1)==b.charAt(y-1)) {
  14. lcs[z][y]=lcs[z-1][y-1]+1;
  15. }
  16. else {
  17. lcs[z][y]=Math.max(lcs[z-1][y], lcs[z][y-1]);
  18. }
  19. }
  20. }
  21. System.out.print("#" + t + " ");
  22. System.out.println(lcs[a.length()][b.length()]);
  23. }
  24. sc.close();
  25. }
  26. }
Add Comment
Please, Sign In to add comment