Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

배우고 느낀 것들

[코드트리] datetime to datetime 본문

파이썬/문제

[코드트리] datetime to datetime

낑깡H 2022. 9. 26. 15:18

🍒 문제 링크 

 

 

🍒 문제 분석

 

 

🍒 내 코드

a, b, c = map(int, input().split())

time = 0

while True:
     if a <= 11 and b <= 11 and c < 11:
          time = -1
          break

     if a == 11 and b == 11 and c == 11:
          break

     c -= 1
     time += 1 
    
     if c == 0:
          b -= 1
          c = 60
    
     if b == 0:
          a -= 1
          b = 24

     

print(time)

 

🍓 내 해결 과정

8행에 break 가 없어 time = -1 인 상태에서 계속 c 이하의 if절이 돌아가서 시간초과가 떴음 ㅠ 

 

 

🌽 다른 사람 코드

# 변수 선언 및 입력
a, b, c = tuple(map(int, input().split()))

# 차이를 계산합니다.
diff = (a * 24 * 60 + b * 60 + c) - (11 * 24 * 60 + 11 * 60 + 11)

# 출력
if diff < 0:
    print(-1)
else:
    print(diff)

 

 

 

🍉 깨달은 점 및 정리

굳이 복잡하게 조건문 안 걸고 계산으로 풀 수 있는 거 있으면 그렇게 푸는 게 가장 좋음,,, 

 

 

 

Comments