#include <stdio.h>
int main() {
int hour, minute;
// Input: Hour and Minute in 24-hour format
printf("Enter time in 24-hour format (HH:MM): ");
scanf("%d:%d", &hour, &minute);
// Check for invalid input
if (hour < 0 || hour > 24 || minute < 0 || minute >= 60) {
printf("Invalid time\n");
return 0;
}
// Conversion logic
if (hour == 0) { // 00:00 in 24-hour -> 12:00 AM
printf("%02d:%02d AM\n", 12, minute);
} else if (hour == 12) { // 12:00 in 24-hour -> 12:00 PM
printf("%02d:%02d PM\n", 12, minute);
} else if (hour > 12 && hour < 24) { // 13-23 hours -> Subtract 12 and append PM
printf("%02d:%02d PM\n", hour - 12, minute);
} else if (hour < 12) { // 01-11 hours -> AM
printf("%02d:%02d AM\n", hour, minute);
} else if (hour == 24) { // 24:00 is 12:00 PM
printf("%02d:%02d PM\n", 12, minute);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIGludCBob3VyLCBtaW51dGU7CiAgICAKICAgIC8vIElucHV0OiBIb3VyIGFuZCBNaW51dGUgaW4gMjQtaG91ciBmb3JtYXQKICAgIHByaW50ZigiRW50ZXIgdGltZSBpbiAyNC1ob3VyIGZvcm1hdCAoSEg6TU0pOiAiKTsKICAgIHNjYW5mKCIlZDolZCIsICZob3VyLCAmbWludXRlKTsKCiAgICAvLyBDaGVjayBmb3IgaW52YWxpZCBpbnB1dAogICAgaWYgKGhvdXIgPCAwIHx8IGhvdXIgPiAyNCB8fCBtaW51dGUgPCAwIHx8IG1pbnV0ZSA+PSA2MCkgewogICAgICAgIHByaW50ZigiSW52YWxpZCB0aW1lXG4iKTsKICAgICAgICByZXR1cm4gMDsKICAgIH0KCiAgICAvLyBDb252ZXJzaW9uIGxvZ2ljCiAgICBpZiAoaG91ciA9PSAwKSB7IC8vIDAwOjAwIGluIDI0LWhvdXIgLT4gMTI6MDAgQU0KICAgICAgICBwcmludGYoIiUwMmQ6JTAyZCBBTVxuIiwgMTIsIG1pbnV0ZSk7CiAgICB9IG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