Programming contests

50 Programming Exercise for Beginners

January 2, 2019, 12:00 AM – December 31, 2019, 12:00 AM

12-Hour Clock

Write a program that reads times in 12-hour format from the standard input until end-of-file (EOF), one per line. The program should write to the standard output the 24-hour times corresponding to the given times. If the hours are less than 10, display the hours with one digit. Minutes should always be displayed with two digits. For example, 12.02am should be converted to 0.02, 11.58am to 11.58, 12.32pm to 12.32, 1.29pm to 13.29, and 10.17pm to 22.17.

Sample Input

  1. 12.02am
  2. 11.58am
  3. 12.32pm
  4. 1.29pm
  5. 10.17pm
download as text file

Output for Sample Input

  1. 0.02
  2. 11.58
  3. 12.32
  4. 13.29
  5. 22.17
download as text file
Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024