fork(1) download
  1. import java.util.*;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Scanner in = new Scanner(System.in);
  7. int tests = Integer.parseInt(in.nextLine());
  8.  
  9. for(int i = 0; i < tests; i++) {
  10. int max = 0;
  11.  
  12. String ag = in.nextLine();
  13. String tom = in.nextLine();
  14.  
  15. while (1){
  16. if (tom.equals("0")) {
  17. break;
  18. }
  19. int cross = LCS(ag,tom);
  20. max = Math.max(cross, max);
  21. tom = in.nextLine();
  22. }
  23.  
  24. // Print the maximum common checkpoints.
  25. System.out.println(max/2 - 1);
  26. }
  27.  
  28. }
  29.  
  30. private static int LCS(String x, String y) {
  31. int M = x.length();
  32. int N = y.length();
  33.  
  34. // opt[i][j] = length of LCS of x[i..M] and y[j..N]
  35. int[][] opt = new int[M+1][N+1];
  36.  
  37. // compute length of LCS and all subproblems via dynamic programming
  38. for (int i = M-1; i >= 0; i--) {
  39. for (int j = N-1; j >= 0; j--) {
  40. if (x.charAt(i) == y.charAt(j))
  41. opt[i][j] = opt[i+1][j+1] + 1;
  42. else
  43. opt[i][j] = Math.max(opt[i+1][j], opt[i][j+1]);
  44. }
  45. }
  46.  
  47. return opt[0][0];
  48. }
  49. }
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
1 2 3 4 5 6 7 8 9 0
1 1 1 1 1 1 2 3 0
1 3 1 3 5 7 8 9 3 4 0
0
1 2 3 4 5 0
4 5 9 0
compilation info
Main.java:15: error: incompatible types
			while (1){
			       ^
  required: boolean
  found:    int
1 error
stdout
Standard output is empty