#C338. Time Conversion: 12-hour to 24-hour Format
Time Conversion: 12-hour to 24-hour Format
Time Conversion: 12-hour to 24-hour Format
This problem requires you to convert a time given in 12-hour AM/PM format to a 24-hour time format.
The input is a single line string representing the time in the format "HH:MM AM/PM" (for example, "02:30 PM"). Your task is to convert this time into its 24-hour equivalent (for example, "14:30").
If the input does not follow the required format, your program should raise an error or terminate with an appropriate error message.
Note: All formulas (if any) are presented in LaTeX format. For instance, to represent hours conversion you might consider \( h_{24} \) computed as:
\( h_{24} = \begin{cases} 0 & \text{if } h_{12} = 12 \text{ and period = AM} \\ h_{12} & \text{if } h_{12} = 12 \text{ and period = PM} \\ h_{12} + 12 & \text{if } h_{12} < 12 \text{ and period = PM} \\ h_{12} & \text{if } h_{12} < 12 \text{ and period = AM} \end{cases} \)
inputFormat
The input consists of a single line containing the time in the 12-hour format "HH:MM AM/PM". For example: 05:45 PM
.
outputFormat
Output the converted time in 24-hour format as a single line string, for example: 17:45
.
12:00 AM
00:00