#K78837. Time Conversion to 24-Hour Format

    ID: 35175 Type: Default 1000ms 256MiB

Time Conversion to 24-Hour Format

Time Conversion to 24-Hour Format

You are given a time in the 12-hour format HH:MM AM/PM and your task is to convert it to the 24-hour format HH:MM. Special care must be taken for midnight and noon.

For example, 02:30 PM should be converted to 14:30 and 12:45 AM should be converted to 00:45.

Note that:

  • Midnight: 12:00 AM is represented as 00:00.
  • Noon: 12:00 PM remains 12:00.

The conversion follows the relation \(H_{24} = \begin{cases}H_{12} + 12 & \text{if } \text{period} = \text{PM and } H_{12} \neq 12,\\ 0 & \text{if } \text{period} = \text{AM and } H_{12} = 12,\\ H_{12} & \text{otherwise.}\end{cases}\)

inputFormat

The input is provided via stdin as a single line containing a time string in the format (\mathrm{HH:MM\ AM/PM}).

outputFormat

Output the converted time in 24-hour format (\mathrm{HH:MM}) to stdout.## sample

02:30 PM
14:30