-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblemH.java
49 lines (45 loc) · 1.16 KB
/
ProblemH.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
import java.util.*;
public class ProblemH{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
while(num-- > 0){
int[][] pos = new int[4][2];
for(int i = 0; i < pos.length; i++){
for(int j = 0; j < pos[i].length; j++){
pos[i][j] = sc.nextInt();
}
}
System.out.println(process(pos));
}
}
public static String process(int[][] pos){
boolean square = true;
boolean rectangle = true;
int[][] distsq = new int[4][4];
for(int i = 0; i < pos.length; i++){
for(int j = 0; j < pos.length; j++){
int xdist = pos[i][0] - pos[j][0];
int ydist = pos[i][1] - pos[j][1];
xdist = xdist*xdist;
ydist = ydist*ydist;
distsq[i][j] = xdist + ydist;
}
Arrays.sort(distsq[i]);
}
for(int i = 0; i < distsq.length - 1 && (square || rectangle); i++){
for(int j = 0; j < distsq[i].length; j++){
if(distsq[i][1] + distsq[i][2] != distsq[i][3]){
square = false;
rectangle = false;
}
if(distsq[i][1] != distsq[i][2]){
square = false;
}
}
}
if(square){ return "SQUARE"; }
else if(rectangle){ return "RECTANGLE"; }
else{ return "NEITHER"; }
}
}