[백준/파이썬] 13363번 풀이

업데이트:



문제 정보


풀이

문제

Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. The API is simple: the compass needle is currently in some direction (between 0 and 359 degrees, with north being 0, east being 90), and is being animated by giving the degrees to spin it. …

입력 요약
The first line of input contains an integer n1 (0 ≤ n1 ≤ 359), the current direction of the needle. The second line of input contains an integer n2 (0 ≤ n2 ≤ 359), the correct direction of the needle.

출력 요약
Output the change in direction that would make the needle spin the shortest distance from n1 to n2. A positive change indicates spinning the needle clockwise, and a negative change indicates spinning the needle counter-clockwise. …

코드

a,b=int(input()),int(input())
if b-a>180:s=b-a-360
elif b-a>-180:s=b-a
else:s=b-a+360
print(s)

설명

핵심은 구현 관점에서 Jonas is developing the JUxtaPhone and is tasked with animating the compass needle. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기