알고리즘/백준

[백준] 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의 값을 뺀 값의 절대값이 가장 작은 값을 출력하도록 하였다.