본문 바로가기
Algorithm & SQL/BAEKJOON

백준 JAVA 1085 직사각형에서 탈출

by YoonJong 2022. 6. 27.
728x90

 


예시

좌표 ( x, y ) 와 좌표 ( w, h ) 가 주어지면 직사각형의 한 변에 최대한 빨리 도달 할 수 있는 거리를 구하는 문제입니다

조건문을 통해 최단거리를 비교해서 구해서 풀었습니다.

 

package BAEKJOON;

import java.util.Scanner;

public class NO1085 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int y = sc.nextInt();
        int w = sc.nextInt();
        int h = sc.nextInt();

        int width = ( w - x ) < x ? ( w - x) : x;
        int height = ( h - y ) < y ? ( h - y ) : y;

        int answer = width < height ? width : height;
        System.out.println(answer);
    }
}
728x90

'Algorithm & SQL > BAEKJOON' 카테고리의 다른 글

백준 JAVA 11721 열 개씩 끊어 출력하기  (0) 2022.06.27
백준 JAVA 2442 별 찍기-5  (0) 2022.06.27
백준 JAVA 10817 세 수  (0) 2022.06.26
백준 JAVA 8958 OX퀴즈  (0) 2022.06.25
백준 JAVA 3052 나머지  (0) 2022.06.25

댓글