문제
https://school.programmers.co.kr/learn/courses/30/lessons/120875
풀이
class Solution {
public int solution(int[][] dots) {
// 점들을 꺼내서 변수에 저장
int x1 = dots[0][0], y1 = dots[0][1];
int x2 = dots[1][0], y2 = dots[1][1];
int x3 = dots[2][0], y3 = dots[2][1];
int x4 = dots[3][0], y4 = dots[3][1];
int answer = 0;
// 조합 1: (0,1) vs (2,3)
double slope1 = (double) (y2 - y1) / (x2 - x1);
double slope2 = (double) (y4 - y3) / (x4 - x3);
if (slope1 == slope2) answer = 1;
// 조합 2: (0,2) vs (1,3)
slope1 = (double) (y3 - y1) / (x3 - x1);
slope2 = (double) (y2 - y4) / (x2 - x4);
if (slope1 == slope2) answer = 1;
// 조합 3: (0,3) vs (1,2)
slope1 = (double) (y4 - y1) / (x4 - x1);
slope2 = (double) (y2 - y3) / (x2 - x3);
if (slope1 == slope2) answer = 1;
return answer;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
[Programmers] Lv.0 | 외계어 사전 | Java (0) | 2025.09.27 |
---|---|
[Programmers] Lv.0 | 저주의 숫자 3 | Java (0) | 2025.09.26 |
[Programmers] Lv.0 | [PCCE 기출문제] 4번 / 병과분류 | Java (0) | 2025.09.22 |
[Programmers] Lv.0 | [PCCE 기출문제] 6번 / 물 부족 | Java (0) | 2025.09.22 |
[Programmers] Lv.0 | [PCCE 기출문제] 5번 / 심폐소생술 | Java (0) | 2025.09.19 |
댓글