【发布时间】: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)
【问题讨论】:
-
请阅读How to debug small programs。您还可以使用Python-Tutor,它有助于逐步可视化代码的执行。
-
如果它解决了您的问题@AritroSinha,请点赞并接受答案
标签: python python-3.x