Files

40 lines
1.2 KiB
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.math.BigDecimal;
import java.util.*;
2017-02-24 00:24:47 -06:00
class Solution {
2017-04-05 18:42:35 -05:00
public static void main(String []args) {
2017-02-16 23:51:56 -06:00
//Input
2017-02-24 00:24:47 -06:00
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String [] s = new String[n+2];
for (int i = 0; i < n; i++) {
s[i] = sc.next();
2017-02-16 23:51:56 -06:00
}
sc.close();
2017-02-24 00:24:47 -06:00
// We want to sort in descending order while preserving the contents
// of each String. A comparator can achieve this for us. We convert
// to BigDecimal inside our comparator so that the change is not
// permanent and our String's form for each number is preserved.
2017-02-16 23:51:56 -06:00
Comparator<String> customComparator = new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
BigDecimal a = new BigDecimal(s1);
BigDecimal b = new BigDecimal(s2);
return b.compareTo(a); // descending order
}
};
Arrays.sort(s, 0, n, customComparator);
//Output
2017-02-24 00:24:47 -06:00
for (int i = 0; i < n; i++) {
2017-02-16 23:51:56 -06:00
System.out.println(s[i]);
}
}
}