【发布时间】:2023-02-15 04:35:05
【问题描述】:
我正在尝试解决 Kattis 上的整数列表挑战。
for _ in range(int(input())):
operation, elements = input(), int(input())
error = False
if elements <= 0:
input()
print('error')
else:
inp_lst = list(map(int, input().strip('[]').split(',')))
for op in operation:
try:
if op == 'R':
inp_lst.reverse()
elif op == 'D':
inp_lst.pop(0)
except IndexError:
print('error')
error = True
break
if not error:
print(inp_lst)
示例输入:
4
RDD
4
[1,2,3,4]
DD
1
[42]
RRD
6
[1,1,2,3,5,8]
D
0
[]
预期输出:
[2,1]
error
[1,2,3,5,8]
error
我的代码确实得到了正确的输出,但它仍然被标记为错误。我不确定我的解决方案有什么问题。任何帮助,将不胜感激。
【问题讨论】:
-
你期望什么,你的程序的结果是什么?
-
您放错了指向 Kattis 的链接。所以现在你的代码似乎输出了它应该输出的内容。
-
“我的代码确实得到了正确的输出,但它仍然被标记为错误。我不确定我的解决方案有什么问题。”我们不为问题分析代码;我们回答有关已发现问题的问题。尝试找到一个输入示例没有导致正确的输出。除此之外,我们还需要问题本身的问题说明;我们需要一个问题描述,相应的代码和问题都是专注的在一、具体问题(不是来自作业或竞赛问题的总体任务)。请阅读How to Ask 和minimal reproducible example 了解更多。
标签: python python-3.x algorithm