[백준1085_파이썬(python)] - 직사각형에서 탈출

경이·2022년 1월 11일
0
post-thumbnail

🔴 문제

직사각형에서 탈출


🟡 Sol

x, y, w, h = map(int,input().split())

if(x>=w and y>=h):
    print(min(x-w, y-h))
elif(x>=w and y<h):
    print(min(x-w, h-y, y))
elif(x<w and y>=h):
    print(min(x, w-x, y-h))
else:
    print(min(x, y, w-x, h-y))

🟢 풀이

경우를 나누어서 풀었는데 다른 풀이들은 경우를 안나눠서 풀었다
왜지? 하고 고민했는데

문제 제한에 써져있음
암튼 조건문 대신 print(min(x, y, w-x, h-y)) 쓰면 될것 같다.


🔵 Ref

https://ooyoung.tistory.com/102

profile
이사중입니다!🌟https://velog.io/@devkyoung2

0개의 댓글

관련 채용 정보