同舟共濟

@piepie01

算出兩年份之間的天數

T = int(input())
for i in range(T):
    a, b = list(map(int, input().split()))
    if a > b:
        a,b = b,a #讓a,b從小排到大
    s = 0
    for j in range(a,b):
        if j % 400 == 0 or j % 100 != 0 and j % 4 == 0: #閏年
            s+=366
        else:
            s+=365
    if s % 7 == 0:
        print("Y")
    else:
        print("N")

數學大師

T = int(input())
for i in range(T):
    a, b = list(map(lambda k:int(k)-1, input().split()))
    week_a = (1 + 28 + (a % 100) + (a % 100) // 4 + a // 100 // 4 - 2 * (a // 100)) % 7
    week_b = (1 + 28 + (b % 100) + (b % 100) // 4 + b // 100 // 4 - 2 * (b // 100)) % 7
    if week_a == week_b:
        print("Y")
    else:
        print("N")

套件大師

import datetime
T = int(input())
for i in range(T):
    a, b = list(map(int, input().split()))
    week_a = datetime.date(a, 1, 1).weekday()
    week_b = datetime.date(b, 1, 1).weekday()
    if week_a == week_b:
        print("Y")
    else:
        print("N")

deck

By piepie01

deck

  • 373