【问题标题】:Codechef giving wrong answer for a program that works locallyCodechef 为在本地运行的程序给出错误答案
【发布时间】:2015-08-18 18:54:05
【问题描述】:

问题陈述:

根据公历,2001 年 1 月 1 日是星期一。如果输入任何年份, 编写一个程序来显示今年 1 月 1 日是什么日子。

输入

第一行包含一个整数 T,即测试用例的总数。然后按照 T 行,每行包含一个整数年。

输出

以小写字母显示当年的 1 月 1 日。

约束

1≤T≤1000

1900≤A,B,C≤2500

例子

输入

3

1994

1991

2014

输出

星期六

星期二

星期三

我提交的解决方案:

import datetime
test = input("Enter no. of test cases ")
while (test):
    year = input("Enter the year ")
    day = datetime.date(int(year),1,1).strftime("%A")
    print (day.lower())
    test = int(test)-1

当我在本地运行时,一切正常。输出与测试用例中给出的相同。为什么在 Codechef 上给出错误的答案?

【问题讨论】:

    标签: python algorithm


    【解决方案1】:

    你不需要提示输入,事实上它会给你几乎所有在线评委的错误答案。以下代码给出了正确答案。

    import datetime
    test = int(input())
    while test:
        year = input()
        day = datetime.date(int(year),1,1).strftime("%A")
        print(day.lower())
        test -= 1
    

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 2018-11-12
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多