아이디어 / 코드 설계
- 60초 = 1분
- 360초 = 1시간
- 먼저 초를 시간이랑 분으로 나누고,
- 그 다음 분에 대해서 60을 넘는지 확인
정답 코드
import sys
input = sys.stdin.readline
h, m, s = map(int, input().split())
d = int(input())
s += d
i = 0
while (True) :
if 0<=h<=23 and 0<=m<=59 and 0<=s<=59 :
break
if s >= 3600 :
h += s // 3600
s -= 3600 * (s//3600)
elif s >= 60 :
m += s // 60
s -= 60 * (s//60)
elif m >= 60 :
h += m//60
m -= 60 * (m//60)
elif h >= 24 :
h = h % 24
print(h, m, s)
'코딩 테스트 > 백준' 카테고리의 다른 글
[Python] 백준 1244 스위치 켜고 끄기 (0) | 2025.01.26 |
---|---|
[Python] 백준 10699 오늘 날짜 (0) | 2025.01.26 |
[Python] 백준 1205 등수 구하기 (0) | 2025.01.24 |
[Python] 백준 23971 ZOAC 4 (0) | 2025.01.24 |
[Python] 백준 2485 가로수 (0) | 2025.01.23 |