본문 바로가기
python-algorithm

백준 14625 냉동식품

by 무적김두칠 2022. 12. 3.

https://www.acmicpc.net/problem/14625

 

14625번: 냉동식품

첫째 줄과 두 번째 줄에 시작시간과 종료시간이 시 H(0 ≤ H ≤ 23)와 분 M(0 ≤ M ≤ 59)이 정수로 빈칸을 사이에 두고 주어진다. 세 번째 줄에는 몇 분이 나오는지 알고 싶은 숫자 N(0 ≤ N ≤ 9)이 주

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def sol(start_total, end_total, target):
    answer = 0
    while str(start_total)!=str(end_total+1):
        str_hh = str(start_total//60)
        str_mm = str(start_total % 60)
        if len(str_mm) == 1:
            str_mm = '0' + str_mm
        if len(str_hh) == 1:
            str_hh = '0' + str_hh
        if target in str_hh or target in str_mm :
            answer += 1
        start_total += 1
    return answer
 
 
if __name__ == '__main__':
    start_hh, start_mm = map(int, input().split())
    start_total = start_hh*60+ start_mm
    end_hh, end_mm = map(int, input().split())
    end_total = end_hh*60+ end_mm
    target = input()
 
    print(sol(start_total, end_total, target))
cs

시간 관련 문제는 시간 단위를 환산해서 계산하시는게 편해요
It is convenient to calculate time-related problems by converting units of time.

반응형

'python-algorithm' 카테고리의 다른 글

백준 15080 Every Second Counts  (0) 2022.12.04
백준 26209 Intercepting Information  (0) 2022.12.04
백준 5698 Tautogram  (0) 2022.12.03
백준 21867 Java Bitecode  (0) 2022.12.03
백준 23627 driip  (0) 2022.12.02

댓글