-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem46.java
49 lines (39 loc) · 1.44 KB
/
Problem46.java
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
package dimikOJ;
import java.util.Scanner;
public class Problem46 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int T = input.nextInt();
while (T < 1 || T > 1000) {
T = input.nextInt();
}
input.nextLine();
String[] inputs = new String[T];
for (int i = 0; i < T; i++) {
String temp = input.nextLine();
String[] tempArray = temp.trim().replaceAll("\\s{2,}", " ").split("\\s");
int a = Integer.parseInt(tempArray[0]);
int b = Integer.parseInt(tempArray[1]);
int c = Integer.parseInt(tempArray[2]);
while (a <= 0 || b <= 0 || c <= 0 || (a + b) <= c || (b + c) <= a || (c + a) <= b) {
temp = input.nextLine();
tempArray = temp.trim().replaceAll("\\s{2,}", " ").split("\\s");
a = Integer.parseInt(tempArray[0]);
b = Integer.parseInt(tempArray[1]);
c = Integer.parseInt(tempArray[2]);
}
inputs[i] = temp.trim().replaceAll("\\s{2,}", " ");
}
input.close();
for (int i = 0; i < inputs.length; i++) {
String[] tempArray = inputs[i].split("\\s");
int a = Integer.parseInt(tempArray[0]);
int b = Integer.parseInt(tempArray[1]);
int c = Integer.parseInt(tempArray[2]);
double semiPerimeter = (a + b + c) / 2;
double area = Math.sqrt(semiPerimeter * (semiPerimeter - a) * (semiPerimeter - b) * (semiPerimeter - c));
System.out.format("Area = %.3f\n", area);
}
}
}