-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoCircles.java
64 lines (51 loc) · 2 KB
/
TwoCircles.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
public class TwoCircles{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int NoOfInputs = in.nextInt();
in.nextLine();
String[] conditions = new String[NoOfInputs];
for(int i =0; i<NoOfInputs; i++) {
conditions[i] = in.nextLine();
}
String[] type = circles(conditions);
for(int i =0; i <type.length; i++) {
System.out.println(type[i]);
}
}
static String[] circles(String[] info) {
String[] result = new String[info.length];
for(int i =0; i < info.length; i++) {
String[] arrInfo = info[i].split(" ");
int r1 = Integer.parseInt(arrInfo[2]);
int r2 = Integer.parseInt(arrInfo[5]);
//type coordinate
int c1 = Integer.parseInt(arrInfo[0]);
int c2 = Integer.parseInt(arrInfo[3]);
if(Integer.parseInt(arrInfo[0]) == 0 ) {
c1 = Integer.parseInt(arrInfo[1]);
c2 = Integer.parseInt(arrInfo[4]);
}
int min1 = c1 - r1;
int max1 = c1 + r1;
int min2 = c2 - r2;
int max2 = c2 + r2;
if(c1 == c2) {
result[i] = "Concentric";
}
else if((max1 > min2 && max1 < max2 && min2 > min1 && min2 < max1) || (max2 > min1 && max2 < max1 && min1 > min2 && min1 < max2)) {
result[i] = "Intersecting";
}
else if(min1 == min2 || min1 == max2 || max1 == max2 || max1 == min2) {
result[i] = "Touching";
}
else if ((min2 > min1 && max2 < max1) || (min1 > min2 && max1 < max2)) {
result[i] = "Disjoint‐Inside";
}
else {
result[i] = "Disjoint‐Outside";
}
}
return result;
}
}