백준 1942 디지털시계 풀이 ( 파이썬 )
https://www.acmicpc.net/problem/1942
1942번: 디지털시계
디지털시계는 일반적으로 시각을 “hh:mm:ss”의 형태로 표현한다. hh는 00 이상 23 이하의 값을, mm과 ss는 00 이상 59 이하의 값을 가질 수 있다. 이러한 형태의 시각에서 콜론(“:”)을 제거하면 “hhm
www.acmicpc.net
내장 라이브러리를 사용해 풀었다.
import datetime
from datetime import timedelta
for i in range(3):
start,end=input().split()
st=int(start.replace(":",""))
ed=int(end.replace(":",""))
stH,stM,stS=map(int,start.split(":"))
edH,edM,edS=map(int,end.split(":"))
stime=datetime.datetime(2021,1,1,stH,stM,stS)
tmp_time=stime.strftime('%H%M%S')
# 1씩 더하기 때문
sec=1
cnt=0
if int(tmp_time)%3==0:
cnt+=1
etime=datetime.datetime(2021,1,1,edH,edM,edS)
etime=etime.strftime('%H%M%S')
while True:
if tmp_time==etime:
break
# sec만큼 증가 (여기서 sec은 1)
stime=stime+timedelta(seconds=sec)
tmp_time=stime.strftime('%H%M%S')
if int(tmp_time)%3==0:
cnt+=1
print(cnt)
[ baekjoon ] 군사 이동 11085번 ( python ) (0) | 2021.06.08 |
---|---|
[ baekjoon ] 전설의 JBNU 12757번 ( python ) (0) | 2021.06.06 |
[ baekjoon ] 전기가 부족해 10423번 ( python ) (0) | 2021.05.30 |
[ baekjoon ] 틱택토 7682번 ( python ) (0) | 2021.05.29 |
[ baekjoon ] 양 3184번, 양치기 꿍 3187번 ( python ) (0) | 2021.05.27 |