Que esta fallando?
Publicado por Pedro (1 intervención) el 13/09/2022 21:15:39
A partir de una Matriz de unos y ceros, debo validar si la misma tiene al menos un cuadrado con vertices de 1, aqui van algunos ejemplos validos:
101
000
101
1 1 1
1 1 1
1 1 1
00011
00011
00000
00101
00101
00000
Aqui van otros ejemplos No validos:
00
00
01
00
00011
00010
La matriz puede tener cualquier dimension.
Esto es lo que hice:
public static Boolean hayCuadrado (char [][] mat){
int filas;
int columnas;
filas= mat.length;
columnas = mat[0].length;
for (int i=0; i< filas; i++){
for(int j=0; j <columnas;j++){
if (mat [i][j]==1){
for (int h=1; h< filas-i; h++){
if (mat[i+h][j]==1 && mat[i][j+h]==1 && mat[i+h][j+h]==1) {
return true;
}
}
}
}
}
return false;
}
}
Creo que la logica esta bien, pero por algun motivo no me valida los casos.
Gracias por su ayuda!
101
000
101
1 1 1
1 1 1
1 1 1
00011
00011
00000
00101
00101
00000
Aqui van otros ejemplos No validos:
00
00
01
00
00011
00010
La matriz puede tener cualquier dimension.
Esto es lo que hice:
public static Boolean hayCuadrado (char [][] mat){
int filas;
int columnas;
filas= mat.length;
columnas = mat[0].length;
for (int i=0; i< filas; i++){
for(int j=0; j <columnas;j++){
if (mat [i][j]==1){
for (int h=1; h< filas-i; h++){
if (mat[i+h][j]==1 && mat[i][j+h]==1 && mat[i+h][j+h]==1) {
return true;
}
}
}
}
}
return false;
}
}
Creo que la logica esta bien, pero por algun motivo no me valida los casos.
Gracias por su ayuda!
Valora esta pregunta


0