forked from SedaKunda/hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigDecimal.java
More file actions
48 lines (34 loc) · 1.42 KB
/
BigDecimal.java
File metadata and controls
48 lines (34 loc) · 1.42 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
/*
Java BigDecimal class can handle arbitrary-precision signed decimal numbers. Lets test your knowledge on them!
You are given nn real numbers, sort them in descending order! Read data from System.in.
Note: To make the problem easier, we provided you the input/output part in the editor. Print the numbers as they appeared in the input, don't change anything. If two numbers represent numerically equivalent values, the output must list them in original order of the input
Input Format
The first line will consist an integer nn, each of the next n lines will contain a real number. nn will be at most 200. The numbers can have at most 300 digits!
Output Format
Print the numbers in descending orders, one number in each line.
*/
import java.math.BigDecimal;
import java.util.*;
class BigDecimal{
public static void main(String []argh)
{
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
String []s=new String[n];
for(int i=0;i<n;i++)
{
s[i] = sc.next();
}
Arrays.sort(s, new Comparator<Object>() {
public int compare(Object a1, Object a2) {
BigDecimal bigDec1 = new BigDecimal((String)a1);
BigDecimal bigDec2 = new BigDecimal((String)a2);
return bigDec2.compareTo(bigDec1);
}
});
for(int i=0;i<n;i++)
{
System.out.println(s[i]);
}
}
}