

-Code
import java.io.*;
import java.util.*;
public class BOJ15803 {
static class StartPos {
int x, y;
public StartPos(String pos) {
String[] split = pos.split(" ");
this.x = Integer.parseInt(split[0]);
this.y = Integer.parseInt(split[1]);
}
}
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
StartPos star1 = new StartPos(br.readLine());
StartPos star2 = new StartPos(br.readLine());
StartPos star3 = new StartPos(br.readLine());
int slope1 = (star1.y - star2.y) * (star2.x - star3.x);
int slope2 = (star2.y - star3.y) * (star1.x - star2.x);
System.out.println(slope1 == slope2 ? "WHERE IS MY CHICKEN?" : "WINNER WINNER CHICKEN DINNER!");
}
}
기울기를 구하여 비교하는 문제이어서 기울기 공식인 y 변화량 / x 변화량을 Math.abs로 계산했습니다.
하지만 이렇게 되면 방향과 0으로 나누어지는 문제가 발생하여 abs를 없애고 이항 하여 곱하기로 바꾸어서 해결했습니다.
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [백준/Java] 6693번 Complicated Route (0) | 2026.02.16 |
|---|---|
| [백준/Java] 16967번 배열 복원하기 (0) | 2026.02.15 |
| [백준/Java] 4201번 Snakes and Ladders (0) | 2026.02.14 |
| [백준/Java] 2303번 숫자 게임 (0) | 2026.02.13 |
| [백준/Java] 2641번 다각형그리기 (0) | 2026.02.13 |