땀두 블로그

[백준] 1085번 - 직사각형에서 탈출 본문

알고리즘/백준

[백준] 1085번 - 직사각형에서 탈출

땀두 2022. 3. 19. 23:06

 

 

import java.util.Scanner;

public class p1085 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

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

		int rst = 1000;
		if (Math.abs(x - w) < rst) {
			rst = Math.abs(x - w);
		}
		if (Math.abs(x) < rst) {
			rst = Math.abs(x);
		}
		if (Math.abs(y - h) < rst) {
			rst = Math.abs(y - h);
		}
		if (Math.abs(y) < rst) {
			rst = Math.abs(y);
		}
		System.out.println(rst);
	}
}
 

x, y좌표에서의 탈출 가능한 0, 0과 w, h의 값을 뺀 값의 절대값이 가장 작은 값을 출력하도록 하였다.

 

'알고리즘 > 백준' 카테고리의 다른 글

[백준] 2775번 - 부녀회장이 될테야  (0) 2022.03.19
[백준] 10250번 - ACM 호텔  (0) 2022.03.19
[백준] 11720번 - 숫자의 합  (0) 2022.03.19
[백준] 8958번 - OX퀴즈  (0) 2022.03.19
[백준] 10950번 - A+B-3  (0) 2022.03.19
Comments