Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#2 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#3 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#4 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#5 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#6 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#7 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#8 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#9 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#10 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#11 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#12 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#13 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#14 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#15 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#16 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#17 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#18 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#19 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#20 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#21 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#22 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#23 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#24 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#25 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#26 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
||
#27 |
Error de compilación
Main.java:1: error: class DistanciaLevenshtein is public, should be declared in a file named DistanciaLevenshtein.java public class DistanciaLevenshtein { ^ 1 error |
public class DistanciaLevenshtein { public static void main(String[] args) { // Leer las dos strings de la entrada String a = System.console().readLine(); String b = System.console().readLine(); // Calcular la distancia de Levenshtein int resultado = calcularDistanciaLevenshtein(a, b); // Imprimir el resultado System.out.println(resultado); } static int calcularDistanciaLevenshtein(String a, String b) { int m = a.length(); int n = b.length(); // Crear una matriz de tamaño (m+1) x (n+1) e inicializarla int[][] matriz = new int[m + 1][n + 1]; for (int i = 0; i <= m; i++) { matriz[i][0] = i; } for (int j = 0; j <= n; j++) { matriz[0][j] = j; } // Llenar la matriz utilizando el algoritmo de Levenshtein for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a.charAt(i - 1) == b.charAt(j - 1)) { matriz[i][j] = matriz[i - 1][j - 1]; } else { matriz[i][j] = 1 + Math.min(Math.min(matriz[i - 1][j], matriz[i][j - 1]), matriz[i - 1][j - 1]); } } } // La última celda de la matriz contiene la distancia de Levenshtein return matriz[m][n]; } }