Files

27 lines
818 B
Java
Raw Permalink Normal View History

2017-02-16 23:51:56 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-02-16 23:51:56 -06:00
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
scan.close();
2017-03-24 00:02:30 -05:00
int hours = Integer.parseInt(str.substring(0,2));
int minutes = Integer.parseInt(str.substring(3,5));
int seconds = Integer.parseInt(str.substring(6,8));
2017-02-16 23:51:56 -06:00
/* Convert to 24-hour format */
if (str.substring(8, 10).equals("PM") && hours != 12) {
hours += 12;
} else if (str.substring(8, 10).equals("AM") && hours == 12) {
hours = 0;
}
2017-03-24 00:02:30 -05:00
System.out.format("%02d:%02d:%02d", hours, minutes, seconds);
2017-02-16 23:51:56 -06:00
}
}