跳到正文

题解

题解:SP3464 CLOCK1 - Clock

lkrqwq约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
2
题目
SP3464

版本

  1. v1当前

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

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

  • canlendar.weekday(y, m, d) : 返回 yy 年 mm 月 dd 日是星期几,从 0∼60 \sim 6 编号,那么星期六就表示 55。

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

Python
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))))
原文