蓝桥杯2024省赛PythonB组——日期问题

题目链接:

https://www.lanqiao.cn/problems/103/learning/?page=1\&first_category_id=1\&name=日期问题

题目内容:


解题思路

python 复制代码
import os
import sys

# 请在此输入您的代码
from datetime import datetime
date_str = input().strip()
A, B, C = map(int, date_str.split('/'))
ans = set()
def con_year(x):
    if x>=60:
        return x+1900
    else:
        return x+2000
# 年月日
try:
    y = con_year(A)
    dt = datetime(y, B, C)
    if datetime(1960,1,1)<=dt<=datetime(2059,12,31):
        ans.add(dt)
except ValueError:
    pass

# 月日年
try:
    y = con_year(C)
    dt = datetime(y, A, B)
    if datetime(1960,1,1)<=dt<=datetime(2059,12,31):
        ans.add(dt)
except ValueError:
    pass

# 日月年
try:
    y = con_year(C)
    dt = datetime(y, B, A)
    if datetime(1960,1,1)<=dt<=datetime(2059,12,31):
        ans.add(dt)
except ValueError:
    pass
# print(ans)

for dt in sorted(ans):
    print(dt.strftime("%Y-%m-%d"))
相关推荐
君义_noip10 小时前
信息学奥赛一本通 1661:有趣的数列 | 洛谷 P3200 [HNOI2009] 有趣的数列
c++·算法·组合数学·信息学奥赛·csp-s
程序员:钧念10 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
数据与后端架构提升之路10 小时前
TeleTron 源码揭秘:如何用适配器模式“无缝魔改” Megatron-Core?
人工智能·python·适配器模式
英英_11 小时前
MATLAB数值计算基础教程
数据结构·算法·matlab
一起养小猫11 小时前
LeetCode100天Day14-轮转数组与买卖股票最佳时机
算法·leetcode·职场和发展
hele_two11 小时前
快速幂算法
c++·python·算法
l1t12 小时前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独
jllllyuz12 小时前
基于子集模拟的系统与静态可靠性分析及Matlab优化算法实现
算法·matlab·概率论
程序员-King.13 小时前
day143—递归—对称二叉树(LeetCode-101)
数据结构·算法·leetcode·二叉树·递归
BlockChain88813 小时前
字符串最后一个单词的长度
算法·go