以下是使用 Python 实现的代码: ```python # 此函数用于判断是否为闰年 def is_leap_year(year): return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) # 获取输入的年份 year = int(input()) # 初始的 1949 年 10 月 1 日是星期六,对应数字 6 total_days = 6 # 计算从 1950 年到输入年份前一年的总天数 for y in range(1950, year): if is_leap_year(y): total_days += 366 else: total_days += 365 # 计算输入年份 1 月 1 日到 10 月 1 日的天数 month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30] if is_leap_year(year): month_days[1] = 29 days_to_oct_1 = sum(month_days) + 1 # 计算总天数 total_days += days_to_oct_1 # 计算星期几 weekday = total_days % 7 print(weekday) ``` 代码解释: 1. `is_leap_year` 函数:用于判断一个年份是否为闰年。闰年的判断规则是:能被 4 整除但不能被 100 整除,或者能被 400 整除。 2. 获取输入年份:使用 `input()` 函数获取用户输入的年份,并将其转换为整数类型。 3. 计算总天数: - 初始化 `total_days` 为 6,表示 1949 年 10 月 1 日是星期六。 - 遍历从 1950 年到输入年份前一年,根据是否为闰年累加每年的天数。 - 计算输入年份 1 月 1 日到 10 月 1 日的天数,考虑闰年 2 月的天数变化。 4. 计算星期几:使用总天数对 7 取模,得到对应的星期几。 5. 输出结果:打印计算得到的星期几。 [2025-07-20 19:59:10 | AI问答 | 558点数解答]