https://www.acmicpc.net/problem/1085
문제
내 풀이
x, y, w, h = map(int, input().split())
dif1 = w-x
dif2 = h-y
if dif1 > x:
shortcut1 = x
else:
shortcut1 = dif1
if dif2 > y:
shortcut2 = y
else:
shortcut2 = dif2
if shortcut1 > shortcut2:
print(shortcut2)
else:
print(shortcut1)
해설
상당히 비효율적으로 짠듯. 가시성을 중요시 생각하긴함.
정답 풀이
x, y, w, h = map(int, input().split())
print(min(x, y, w-x, h-y))
출처:https://ooyoung.tistory.com/102
해석
min(), max() 등의 python 내장 함수 등장.
min함수는 min(iterable) 형태로 사용한다. 괄호( ) 안에 문자열, 리스트와 같은 반복 가능한 iterable 자료형을 입력하면 요소들 중 최솟값을 반환한다.
'sw사관학교 정글 2기 > 01 기초,재귀,완전탐색, 정렬' 카테고리의 다른 글
백준 10950번 -A+B-3- with.Python3 (0) | 2021.08.07 |
---|---|
백준 2739번 -구구단- with.Python3 (1) | 2021.08.07 |
백준 2753번 -윤년- with.Python3 (0) | 2021.08.07 |
백준 9498번 -시험 성적- with.Python3 (0) | 2021.08.07 |
백준 2588번 -곱셉- with.Python3 (0) | 2021.08.07 |
댓글