umilove98의 블로그

백준 1085 Java 본문

algorithm/백준

백준 1085 Java

umilove98 2021. 7. 28. 12:26
반응형

 

직사각형의 경계선까지 가는 경우는 x -> w , x -> 0, y -> h, y -> 0 으로 4 가지가 있다 

그 중 최소값을 찾으면 된다. 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
 
public class Q1085 {
 
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int x = Integer.parseInt(st.nextToken());
        int y = Integer.parseInt(st.nextToken());
        int w = Integer.parseInt(st.nextToken());
        int h = Integer.parseInt(st.nextToken());
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(x);
        list.add(y);
        list.add(w-x);
        list.add(h-y);
        
        System.out.println(Collections.min(list));
 
    }
 
}
 
cs
반응형

'algorithm > 백준' 카테고리의 다른 글

백준 1343 Java  (0) 2021.07.29
백준 1331 Java  (0) 2021.07.28
백준 1316 Java  (0) 2021.07.27
백준 1009 Java  (0) 2021.07.27
백준 1292 Java  (0) 2021.07.26