我收到此代码的错误:
#Finding largest number
elements = []
nl = input("Enter number of lines :")
for i in range(0,int(nl)):
print("Enter number of elements in line", i+1, ": ")
ne = input()
elements = [None]*int(ne)
print("Enter elements :")
maximum = 0
for j in range(0,int(ne)):
elements[j] = input()
for j in range(0,int(ne)):
if int(elements[j]) > maximum:
maximum = int(elements[j])
print("Maximum number in line", i+1, "is", maximum,"\n\n")
我在codechef上提交了这段代码,它显示了运行时错误(NZEC)错误
请帮忙!
答案 0 :(得分:1)
我非常确定你的数字是在一行上输入的,用空格分隔。你需要做一些改变。
HashSet<Integer> numbersLessThan10 = removeAllNumbersMoreThan10(a);
或者,你可以用
替换max-finding循环for i in range(0, int(input())):
elements = []
maximum = -float('inf')
ne = int(input())
elements = list(map(int, input().split())) # assuming space separated integers
for e in elements:
if e > maximum:
maximum = e
print("Maximum number in line", i+1, "is", maximum, "\n\n")
如果您的数字是换行符,请创建一个空列表并循环追加。
maximum = max(elements)