Skip to content

Commit 1d27507

Browse files
committed
time in words done
1 parent 2e6b7bc commit 1d27507

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

src/com/hackerrank/practice/RandomTest.java src/me/ramswaroop/misc/RandomTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.ramswaroop.practice;
1+
package me.ramswaroop.misc;
22

33
import java.util.Random;
44

src/com/hackerrank/practice/SPOJ1.java src/me/ramswaroop/misc/SPOJ1.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.ramswaroop.practice;
1+
package me.ramswaroop.misc;
22

33
import java.util.ArrayList;
44
import java.util.List;

0 commit comments

Comments
 (0)