-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBigNumberJavaBigDecimalSolution.java
More file actions
66 lines (60 loc) · 987 Bytes
/
BigNumberJavaBigDecimalSolution.java
File metadata and controls
66 lines (60 loc) · 987 Bytes
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.math.BigDecimal;
import java.util.*;
/**
* @see ../bignumber_java-bigdecimal-task.pdf
*/
class BigNumberJavaBigDecimalSolution {
public static void main(String[] args) {
//Input
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();
}
sc.close();
// Implementation begin
boolean ordered = false;
while (!ordered) {
ordered = true;
for (int i = 0; i < n - 1; i++) {
BigDecimal firstNumber = new BigDecimal(s[i]);
BigDecimal secondNumber = new BigDecimal(s[i + 1]);
if (firstNumber.compareTo(secondNumber) == -1) {
String temp = s[i];
s[i] = s[i + 1];
s[i + 1] = temp;
ordered = false;
}
}
}
// Implementation end
//Output
for (int i = 0; i < n; i++) {
System.out.println(s[i]);
}
}
/* Testcase 1
INPUT:
9
-100
50
0
56.6
90
0.12
.12
02.34
000.000
OUTPUT:
90
56.6
50
02.34
0.12
.12
0
000.000
-100
*/
}