문제
3029번: 경고
첫째 줄에 현재 시간이 hh:mm:ss 형식으로 주어진다. (시, 분, 초) hh는 0보다 크거나 같고, 23보다 작거나 같으며, 분과 초는 0보다 크거나 같고, 59보다 작거나 같다. 둘째 줄에는 나트륨을 던질 시간
www.acmicpc.net
코드
My answer
import sys
input=sys.stdin.readline
current=input()
throw=input()
if(current==throw):
print("24:00:00")
else:
current=int(current[0:2])*3600+int(current[3:5])*60+int(current[6:8])
throw=int(throw[0:2])*3600+int(throw[3:5])*60+int(throw[6:8])
if(current>throw):
throw+=24*3600
time=throw-current
print("%02d:%02d:%02d"%(time//3600,time%3600//60,time%3600%60))
Another answer
def f():
h,m,s=map(int,input().split(":"))
return 60*(60*h+m)+s
n,w=f(),f()
M=w-n+86400*(n>=w)
print('%02d:%02d:%02d'%(M//3600,M%3600//60,M%3600%60))
풀이
그냥 전체시간을 초로 바꿔서 계산하면편리하다 출력하는 것만 출력형식을 잘 맞춰주면 된다.
728x90
반응형
'코딩테스트 > 백준[Python]' 카테고리의 다른 글
[Python] 백준 #9046- 복호화 (0) | 2022.01.15 |
---|---|
[Python] 백준 #11365- !밀비 급일 (0) | 2022.01.15 |
[Python] 백준 #18511- 큰 수 구성하기[try_again] (0) | 2022.01.14 |
[Python] 백준 #5568- 카드 놓기 (0) | 2022.01.14 |
[Python] 백준 #1912 - 연속합 [try_again] (0) | 2022.01.12 |