문제

N시 59분 59초 까지 3이 하나라도 나오는 경우의 수를 모두 구하는 문제

✍️ 나의 풀이


  • 간단하게 60이 되면 분, 시를 증가 시켰고 3이 있으면 count를 증가

🛠 나의 코드


hour, minute, second = 0, 0, 0
count = 0
while True:
    if '3' in str(hour)+str(minute)+str(second):
        count += 1
    second += 1
    if second == 60:
        second = 0
        minute += 1
    if minute == 60:
        minute = 0
        hour += 1
    if hour == n+1:
        break
print(count)

✍️ 다른 풀이


  • 초, 분이 60까지 인 것을 이용해 반복문으로 간단히 구현함

🛠 다른 코드


h = int(input())
count = 0
for i in range(h+1):  # hour
    for j in range(60):  # minute 0 ~ 59
        for k in range(60):  # second 0 ~ 59
            if '3' in str(i) + str(j) + str(k):
                count += 1
print(count)

📝 정리


  • 시간 문제에 익숙해지자

🎈 참고


profile
Go Go

0개의 댓글