직사각형의 경계선까지 가는 거리의 최솟값을 구하는 함수 구현하기
한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램을 작성하시오.
input | output |
6 2 10 3 | 1 |
1 1 5 5 | 1 |
653 375 1000 1000 | 347 |
161 181 762 375 | 161 |
x,y,w,h = map(int,input().split())
d_left = x # distance from x to left boundary (0)
d_right = w - x # distance from x to right boundary (w)
d_bottom = y # distance from y to bottom boundary (0)
d_top = h - y # distance from y to top boundary (h)
min_distance = min(d_left, d_right, d_bottom, d_top)
print(min_distance)