● 문제
●풀이
직사각형 내에 현재 위치 (x,y) 에서 십자가 모양의 4개의 길이 중 최솟값을 구하는 문제.4개의 길이를 구해서, 배열에 넣고 오름차순으로 분류를 해서 가장 작은 수를 출력하였다.
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int x = in.nextInt();
int y = in.nextInt();
int w = in.nextInt();
int h = in.nextInt();
int a = x - 0;
int b = w - x;
int c = h - y;
int d = y - 0;
int[] arr = {a,b,c,d};
Arrays.sort(arr);
System.out.println(arr[0]);
}
}
'백준' 카테고리의 다른 글
[백준] 2292 벌집_ JAVA (0) | 2023.06.03 |
---|---|
[백준] 2231 분해합_ JAVA (0) | 2023.06.03 |
[백준] 1978 소수 찾기_ JAVA (0) | 2023.06.03 |
[백준] 10250 ACM 호텔_ JAVA (1) | 2023.06.03 |
[백준] 4153 직각삼각형 _ JAVA (0) | 2023.06.02 |