| 
 | 1 | +package com.hackerrank.algorithms.implementation;  | 
 | 2 | + | 
 | 3 | +import java.util.Scanner;  | 
 | 4 | + | 
 | 5 | +/**  | 
 | 6 | + * Created by ramswaroop on 29/05/2016.  | 
 | 7 | + */  | 
 | 8 | +public class TheTimeInWords {  | 
 | 9 | +    public static void main(String[] args) {  | 
 | 10 | +        Scanner in = new Scanner(System.in);  | 
 | 11 | +        int h = in.nextInt();  | 
 | 12 | +        int m = in.nextInt();  | 
 | 13 | +        String timeInWords;  | 
 | 14 | +        String[] words = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",  | 
 | 15 | +                "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",  | 
 | 16 | +                "nineteen", "twenty", "twenty one", "twenty two", "twenty three", "twenty four", "twenty five", "twenty six",  | 
 | 17 | +                "twenty seven", "twenty eight", "twenty nine"};  | 
 | 18 | + | 
 | 19 | +        if (m == 0) {  | 
 | 20 | +            timeInWords = words[h] + " o' clock";  | 
 | 21 | +        } else if (m == 1) {  | 
 | 22 | +            timeInWords = words[m] + " minute past " + words[h];  | 
 | 23 | +        } else if (m == 15) {  | 
 | 24 | +            timeInWords = "quarter past " + words[h];  | 
 | 25 | +        } else if (m < 30) {  | 
 | 26 | +            timeInWords = words[m] + " minutes past " + words[h];  | 
 | 27 | +        } else if (m == 30) {  | 
 | 28 | +            timeInWords = "half past " + words[h];  | 
 | 29 | +        } else if (m == 45) {  | 
 | 30 | +            timeInWords = "quarter to " + words[(h == 12) ? h - 11 : h + 1];  | 
 | 31 | +        } else if (60 - m == 1) {  | 
 | 32 | +            timeInWords = words[60 - m] + " minute to " + words[(h == 12) ? h - 11 : h + 1];  | 
 | 33 | +        } else {  | 
 | 34 | +            timeInWords = words[60 - m] + " minutes to " + words[(h == 12) ? h - 11 : h + 1];  | 
 | 35 | +        }  | 
 | 36 | +        System.out.println(timeInWords);  | 
 | 37 | +    }  | 
 | 38 | +}  | 
0 commit comments