【问题标题】:Correct sample output but not getting accepted on codechef正确的示例输出但未在 codechef 上被接受
【发布时间】:2020-12-17 16:33:31
【问题描述】:

我正在尝试使用 Python 语言解决这个初学者问题:https://www.codechef.com/problems/ZUBTRCNT

我已经编写了在示例案例中给出正确输出的代码。它提供与其他接受的答案相同的输出。但是我的代码没有被接受。

供参考: (我的代码不被接受):https://www.codechef.com/viewsolution/40506063

case=int(input())
for c in range(case):
    l,k=map(int,input().split())
    n = l - k + 1
    sum = n * (n + 1) // 2
    print("Case {}:".format(c+1),sum)

(其他人成功回答):https://www.codechef.com/viewsolution/39844942

t=int(input())
for i in range(0,t):
   l,k=map(int,input().split())
   if(l<k):
      print("Case "+str(i+1)+":","0")
   else:
      m=l-k+1
      m=m*(m+1)//2
      print("Case "+str(i+1)+":",m)

【问题讨论】:

标签: python python-3.x


【解决方案1】:

这是因为你错过了一个重要的测试用例l&lt;k

看看下面的代码,它在 Codechef 上有 Accepted 判断:

case=int(input())
for c in range(case):
    l,k=map(int,input().split())
    if(l<k):
      print("Case {}:".format(c+1),0)
    else:
        n = l - k + 1
        sum = n * (n + 1) // 2
        print("Case {}:".format(c+1),sum)

判决:

【讨论】:

  • 哦。感谢您的帮助。我只是注意到,巧合的是,在我所有的测试用例中,n 都变成了 0。我以为我得到了正确的答案。
猜你喜欢
  • 2020-02-23
  • 2019-08-29
  • 1970-01-01
  • 2019-01-05
  • 1970-01-01
  • 1970-01-01
  • 2021-10-01
  • 2017-04-04
  • 2013-05-15
相关资源
最近更新 更多