1002번 - 터렛
import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int[][] testCase = new int[3][7]; int x, y, answer = 0; double r; for(int i = 0; i < num; i++) { for(int j = 0; j < 6; j++) { testCase[i][j] = sc.nextInt(); } x = Math.abs(testCase[i][0] - testCase[i][3]); y = Math.abs(testCase[i][1] - testCase[i][4]); r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); if(testCase[i][2] > testCase[i][5]) { if(testCase[i][2] + testCase[i][5] < r || testCase[i][2] - testCase[i][5] > r) answer = 0; else if(testCase[i][2] + testCase[i][5] == r || testCase[i][2] - testCase[i][5] == r) answer = 1; else if((testCase[i][2] - testCase[i][5]) < r || r < (testCase[i][2] + testCase[i][5])) answer = 2; else answer = -1; } else { if(testCase[i][5] + testCase[i][2] < r || testCase[i][5] - testCase[i][2] > r) answer = 0; else if(testCase[i][5] + testCase[i][2] == r || testCase[i][5] - testCase[i][2] == r) answer = 1; else if((testCase[i][5] - testCase[i][2]) < r || r < (testCase[i][5] + testCase[i][2])) answer = 2; else answer = -1; } System.out.println(answer); } }}
댓글을 작성하려면 로그인해야 합니다.
leedohyeon0502 2년 전
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[][] testCase = new int[3][7];
int x, y, answer = 0;
double r;
for(int i = 0; i < num; i++) {
for(int j = 0; j < 6; j++) {
testCase[i][j] = sc.nextInt();
}
x = Math.abs(testCase[i][0] - testCase[i][3]);
y = Math.abs(testCase[i][1] - testCase[i][4]);
r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
if(testCase[i][2] > testCase[i][5]) {
if(testCase[i][2] + testCase[i][5] < r || testCase[i][2] - testCase[i][5] > r)
answer = 0;
else if(testCase[i][2] + testCase[i][5] == r || testCase[i][2] - testCase[i][5] == r)
answer = 1;
else if((testCase[i][2] - testCase[i][5]) < r || r < (testCase[i][2] + testCase[i][5]))
answer = 2;
else
answer = -1;
} else {
if(testCase[i][5] + testCase[i][2] < r || testCase[i][5] - testCase[i][2] > r)
answer = 0;
else if(testCase[i][5] + testCase[i][2] == r || testCase[i][5] - testCase[i][2] == r)
answer = 1;
else if((testCase[i][5] - testCase[i][2]) < r || r < (testCase[i][5] + testCase[i][2]))
answer = 2;
else
answer = -1;
}
System.out.println(answer);
}
}
}