题解:SP3464 CLOCK1 - Clock

· · 题解

介绍一种码量小的 Python 解法。

首先我们要知道 calendar 库,Python 中的日历模块。这个库里有一个非常好用的函数:

那么我们只要对于每个询问枚举月份即可,注意非闰年的时候 2 月是没有 29 日的,需要特判。

import sys,calendar
for y in map(int,sys.stdin):print(sum(calendar.weekday(y,m,29)==5 for m in range(1,13) if m!=2 or (y%4==0 and (y%100!=0 or y%400==0))))