蓝桥杯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"))
相关推荐
Miraitowa_cheems12 小时前
LeetCode算法日记 - Day 73: 最小路径和、地下城游戏
数据结构·算法·leetcode·职场和发展·深度优先·动态规划·推荐算法
野蛮人6号12 小时前
力扣热题100道之560和位K的子数组
数据结构·算法·leetcode
Swift社区13 小时前
LeetCode 400 - 第 N 位数字
算法·leetcode·职场和发展
fengfuyao98514 小时前
BCH码编译码仿真与误码率性能分析
算法
哲Zheᗜe༘14 小时前
了解学习Python编程之python基础
开发语言·python·学习
小白不想白a14 小时前
每日手撕算法--哈希映射/链表存储数求和
数据结构·算法
剪一朵云爱着15 小时前
力扣2080. 区间内查询数字的频率
算法·leetcode
落日漫游15 小时前
数据结构笔试核心考点
java·开发语言·算法
麦麦大数据15 小时前
F024 RNN+Vue+Flask电影推荐可视化系统 python flask mysql 深度学习 echarts
python·rnn·深度学习·vue·echarts·电影推荐
workflower15 小时前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程