한수는 지금 (x, y)에 있다. 직사각형은 각 변이 좌표축에 평행하고, 왼쪽 아래 꼭짓점은 (0, 0), 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램을 작성하시오.
첫째 줄에 x, y, w, h가 주어진다.
첫째 줄에 문제의 정답을 출력한다.
6 2 10 3
1 1 5 5
653 375 1000 1000
1
1
347
import java.util.Scanner;
public class Main {
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 cnt1 = ((w-x)<x? (w-x) : x);
int cnt2 = ((h-y)<y? (h-y) : y);
if(cnt1<cnt2) {
System.out.println(cnt1);
}else {
System.out.println(cnt2);
}
}
}