본문 바로가기
Beakjoon&프로그래머스/Java

[백준/Java] 15803번 PLAYERJINAH’S BOTTLEGROUNDS

by 현장 2026. 2. 14.

-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를 없애고 이항 하여 곱하기로 바꾸어서 해결했습니다.