AcWing 1341. 十三号星期五(Python)
原题链接
简单
作者:
习学学
,
2021-01-20 11:17:21
,
所有人可见
,
阅读 344
模拟 Python代码
N = int(input())
month_to_days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
frequency = [0] * 7
def is_leapyear(y):
if (y % 4 == 0 and y % 100 != 0) or y % 400 == 0: return True
return False
start = 0 # 1900/1/13开始是星期六
for year in range(1900, 1900+N):
for month in range(1, 13):
frequency[start] += 1 # 将本月13号的星期记录下来
days = month_to_days[month] # 本月的天数
if month == 2 and is_leapyear(year): days = 29
start = (start + days) % 7 # 下个月月13号的星期
print(" ".join(str(x) for x in frequency))