피드백&소통 #1
junnyontop-pixel
started this conversation in
General
Replies: 3 comments 4 replies
-
|
오 안녕하세요 |
Beta Was this translation helpful? Give feedback.
1 reply
-
import sys
# 1. 윤년 판별 함수
def is_leap(year):
# 조건 1: 400으로 나누어 떨어지면 윤년
if year % 400 == 0:
return True
elif year % 100 == 0:
return False
elif year % 4 == 0:
return True
else:
return False
# 2. 각 달의 일수를 반환하는 함수
def get_days_in_month(year, month):
# 기본 일수 리스트 (0번 인덱스는 비워둠)
days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
# 만약 2월이고 윤년이라면? 29를 반환
# [이곳에 조건을 작성해보세요]
return days[month]
# 3. 1년 1월 1일부터 해당 날짜까지의 총 일수를 구하는 함수
def get_total_days(y, m, d):
total = 0
# (1) 1년부터 y-1년까지의 모든 일수 더하기
for i in range(1, y):
if is_leap(i):
total += 366
else:
total += 365
# (2) 해당 연도(y)의 1월부터 m-1월까지의 일수 더하기
for i in range(1, m):
total += get_days_in_month(y, i)
# (3) 마지막으로 일을 더하기
total += d
return total
def solve():
# 입력 받기 (연, 월, 일 순서)
y1, m1, d1 = map(int, sys.stdin.readline().split())
y2, m2, d2 = map(int, sys.stdin.readline().split())
# 4. "gg" 조건 판별 (천 년 이상 차이)
# y1년 m1월 d1일에 1000년을 더한 날짜와 y2년 m2월 d2일을 비교
is_gg = False
if y2 - y1 > 1000:
is_gg = True
elif y2 - y1 == 1000:
if m2 > m1 or (m2 == m1 and d2 >= d1):
is_gg = True
if is_gg:
print("gg")
else:
# 5. 두 날짜의 총 일수 차이 계산
d1_total = get_total_days(y1, m1, d1)
d2_total = get_total_days(y2, m2, d2)
print(f"D-{d2_total - d1_total}")
if __name__ == "__main__":
solve() |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
안녕하세요 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
안녕하세요!
Beta Was this translation helpful? Give feedback.
All reactions