- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0014.java
More file actions
Latest commit
48 lines (42 loc) · 1.44 KB
/
Copy pathHackerrankJava0014.java
File metadata and controls
48 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
importjava.math.BigDecimal;
importjava.util.Arrays;
importjava.util.Comparator;
importjava.util.Scanner;
publicclassHackerrankJava0014 {
publicstaticvoidmain(String[] args) {
// Java BigDecimal
// https://www.hackerrank.com/challenges/java-bigdecimal/problem?isFullScreen=true
// Input
Scannersc = newScanner(System.in);
intn = sc.nextInt();
String[] s = newString[n + 2];
for (inti = 0; i < n; i++) {
s[i] = sc.next();
}
sc.close();
// -------------------------------------------------------------------------------------------------
// --- You need to add this lines for solution hackerrank provides all other lines for challange ---
// -------------------------------------------------------------------------------------------------
Arrays.sort(s, newComparator<String>() {
@Override
publicintcompare(Stringo1, Stringo2) {
if (o2 == null) {
return -1;
}
if (o1 == null) {
return1;
}
BigDecimala = newBigDecimal(o1);
BigDecimalb = newBigDecimal(o2);
returnb.compareTo(a);
}
});
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Output
for (inti = 0; i < n; i++) {
System.out.println(s[i]);
}
}
}