[백준/파이썬] 18063번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 18063번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Kai is listening to his favourite jazz playlist. He likes to turn on crossfading between songs, so during the last seconds of a song, it will slowly fade out while the next one fades in. This happens between any two consecutive songs, but the beginning of the first song and the end of the last song will be played normally.
Determine the total amount of time it takes Kai to listen to the whole playlist.
입력 요약
The input consists of:
- Two integers n and c (1 ≤ n ≤ 100, 1 ≤ c ≤ 10), giving the number of songs and the crossfade time in seconds. …
출력 요약
Output a string of the form hh:mm:ss, giving the total time it takes to listen through the whole playlist (with two digits for the number of whole hours, two digits for the number of remaining whole minutes, and two digits for the remaining seconds).
코드
n,c=map(int,input().split())
l,r=[list(map(int,input().split(':')))for _ in range(n)],-c*(n-1)
for i in l:r+=i[0]*60+i[1]
print('%02d:%02d:%02d'%(r//3600,r%3600//60,r%60))
설명
핵심은 구현 관점에서 Kai is listening to his favourite jazz playlist. He likes to turn on crossfading between songs, so during the last seconds of a song, it will slowly f …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기