|

[JAVA | 백준 1085] 직사각형에서 탈출

· 테크· Java
Java
백준 1085번 문항  www.acmicpc.net/problem/1085

 

풀이

4가지 정수를 입력받고 좌표를 생각해보면 구할 수 있다.

Math.min을 이용해서 각 값을 비교해서 최단거리의 직사각형의 변까지 거리를 계산한다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.Scanner;
 
public class Math_1085 {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();   
        sc.nextLine();
        
        System.out.println(Math.min(Math.min(x, h-x), Math.min(y,w-y)));
        sc.close();
    }
 
}
cs

Comments

No comments yet. Be the first!

    319 posts in 테크

    15 / 319