package org.example;

import java.util.Scanner;

public class ej1 {

    static void main(String[] args) {
        //Leer una entrada HHMM → Implementar una fucnión a12h(int hhmm).
        Scanner sc = new Scanner(System.in);
        System.out.println("Introduzca una hora formato 24H HHMM");
        String h24 = sc.nextLine();
        String h12 = a12h(h24);
        System.out.println(h12);
    }
    public static String a12h(String h24){
        int horas = Integer.parseInt(h24)/100; //04 50               [0450 / 100 COCIENTE =4 | RESTO 50]
        int minutos = Integer.parseInt(h24)%100; //0450

        int horasInt = horas;
        int minutosInt = minutos;

        //2050
        //1940
        //0510

        String tipo = horasInt>=12 ? "PM" : "AM"; //AM / PM
        int horasFinales = horasInt>12 ? horasInt-12 : horasInt;
        return horasFinales+":"+minutos+" "+tipo;
    }
    public static String a12h_OLD(String h24){
        String horas = h24.substring(0,2); //0450
        String minutos = h24.substring(2,4); //0450
        int horasInt = Integer.parseInt(horas);
        String tipo = horasInt>=12 ? "PM" : "AM"; //AM / PM
        int horasFinales = horasInt>12 ? horasInt-12 : horasInt;
        return horasFinales+":"+minutos+" "+tipo;
    }
}
