corregir ajedrez aceptarelreto

This commit is contained in:
PC de clase committed 2026-10-15 13:42:48 +02:00
1 parent 4070327d70
commit 58030ec54a
3 files changed
+18 -15

No files matched your search

+1 -2
View File
@@ -1,7 +1,7 @@
import java.util.Scanner; import java.util.Scanner;
public class P112_RadaresDeTramo { public class P112_RadaresDeTramo {
public static void main() { public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int distancia = 0; // Distancia entre las cámaras (metros) int distancia = 0; // Distancia entre las cámaras (metros)
int velPermitida = 0; // Velocidad máxima permitida (Km/h) int velPermitida = 0; // Velocidad máxima permitida (Km/h)
@@ -19,7 +19,6 @@ public class P112_RadaresDeTramo {
} }
// Salir del bucle // Salir del bucle
if (distancia == 0 && velPermitida == 0 && tiempo == 0) { if (distancia == 0 && velPermitida == 0 && tiempo == 0) {
System.out.println("SALIR");
break; break;
} }
// Calcular // Calcular
+11 -7
View File
@@ -1,23 +1,27 @@
import java.util.Scanner; import java.util.Scanner;
void main() { public class P164_AreaRectangulo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
// Coordenadas de las esquinas opuestas // Coordenadas de las esquinas opuestas
int ax, ay, bx, by; int ax, ay, bx, by;
// Longitud de lados // Longitud de lados
int l1, l2; int l1 = 0, l2 = 0;
// Area del rectangulo // Area del rectangulo
int area; int area;
while (true) { while (true) {
System.out.print("Introduce las coordenadas del rectángulo (ax ay bx by): ");
ax = sc.nextInt(); ax = sc.nextInt();
ay = sc.nextInt(); ay = sc.nextInt();
bx = sc.nextInt(); bx = sc.nextInt();
by = sc.nextInt(); by = sc.nextInt();
// Ternario para obtener resta positiva
l1 = (ax < bx) ? bx - ax : ax - bx; // Omitir casos de prueba
l2 = (ay < by) ? by - ay : ay - by; if(ax > bx || ay > by) break;
l1 = bx - ax;
l2 = by - ay;
area = l1 * l2; area = l1 * l2;
System.out.println("El área es: " + area); System.out.println(area);
}
} }
} }
+6 -6
View File
@@ -1,18 +1,18 @@
// Convertir la posición del tablero de ajedrez en números // Convertir la posición del tablero de ajedrez en números
// a notación algebraica. Ex: 5 2 -> d 2 // a notación algebraica. Ex: 5 2 -> d 2
void main() {
import java.util.Scanner;
public class P481_Ajedrez {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int h = 0, v = 0; int h = 0, v = 0;
do { do {
System.out.println("Introduce la casilla del tablero con numeros: ");
h = sc.nextInt(); h = sc.nextInt();
v = sc.nextInt(); v = sc.nextInt();
if (h == 0 && v == 0) break; if (h == 0 && v == 0) break;
if (h < 1 || v < 1 || h > 8 || h > 8) {
System.out.println("ERROR: Casillas inválidas");
return;
}
char letra = (char) ((8 - h) + (int) ('a')); char letra = (char) ((8 - h) + (int) ('a'));
System.out.printf("%c%d\n", letra, v); System.out.printf("%c%d\n", letra, v);
} while (true); } while (true);
} }
}