자바/백준

백준 1085번 / 직사각형에서 탈출

모자 2021. 10. 10. 23:51
728x90
반응형

import java.util.Arrays;
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 arr[]= {x, y, w-x, h-y}; //x, y, w-x, h-y를 한 배열에 넣는다.
		Arrays.sort(arr); // 배열을 작은순서대로 정렬
		System.out.println(arr[0]); //가장 작은 값을 출력
	}
}

이번 문제는 x, y, w-x, h-y의 길이를 각각 비교해 가장 작은 값을 출력하면 끝이나는 문제이다.