CCF Python题解(100分)201503-3 节日

CCF Python题解(100分)201503-3 节日

a, b, c, y1, y2 = map(int, input().split())
data = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]


#
def day(y1, days=0):
    for i in range(1850, y1):
        days += 365
        if leapyear(i):
            days += 1
    return days  #


def leapyear(year):
    if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):

        return True
    else:
        return False


defaultdays = day(y1)
for i in range(y1, y2 + 1):

    if leapyear(i):  # 是闰年
        data[2] = 29
    currentday = defaultdays
    for j in range(a):
        currentday += data[j]
    count = (currentday + 2) % 7  # +2是因为1850/01/01是周二
    if count == 0:
        count = 7
    # 该月1号在输入的周几之后  正常加
    if count > c:
        date = 7 * b + c - count + 1  # +1
    # 该月1号在输入的周几之前 (b-1)*7
    else:
        date = 7 * (b - 1) + c - count + 1  # +1
    # 格式化
    if date <= data[a]:
        if a < 10:
            month = "0" + str(a)
        else:
            month = str(a)
        if date < 10:
            newdate = "0" + str(date)
        else:
            newdate = str(date)
        print(str(i) + '/' + month + '/' + newdate)

    else:
        print("none")
    defaultdays += 365
    if leapyear(i):  # 是闰年
        defaultdays += 1
        data[2] = 28


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值