| import java.io.*; |
| import java.math.*; |
| import java.security.*; |
| import java.text.*; |
| import java.util.*; |
| import java.util.concurrent.*; |
| import java.util.function.*; |
| import java.util.regex.*; |
| import java.util.stream.*; |
| import static java.util.stream.Collectors.joining; |
| import static java.util.stream.Collectors.toList; |
|
|
| class Result { |
|
|
| /* |
| * Complete the 'timeConversion' function below. |
| * |
| * The function is expected to return a STRING. |
| * The function accepts STRING s as parameter. |
| */ |
|
|
| public static String timeConversion(String s) { |
| // Write your code here |
| String hour = s.substring(0,2); |
| String rest = s.substring(3,8); |
| String amOrPm = s.substring(8); |
|
|
| String newHour = hour; |
| if(amOrPm.equals("AM") && Integer.valueOf(hour) == 12) |
| newHour = "00"; |
| |
| else if(amOrPm.equals("PM") && Integer.valueOf(hour) != 12) |
| newHour = String.valueOf(12 + Integer.valueOf(hour)); |
| |
| return newHour + ":" + rest; |
| } |
|
|
| } |
|
|
| public class Solution { |
| public static void main(String[] args) throws IOException { |
| BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); |
| BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); |
|
|
| String s = bufferedReader.readLine(); |
|
|
| String result = Result.timeConversion(s); |
|
|
| bufferedWriter.write(result); |
| bufferedWriter.newLine(); |
|
|
| bufferedReader.close(); |
| bufferedWriter.close(); |
| } |
| } |
No comments:
Post a Comment