python逐个输出列表元素_在Python3中逐个阅读列表中的元素我正在写⼀个程序,以到排序后的名单在每个通⾏证的排名。
我的程序在这⾥:import sys
# No. of Students considered
n = int(input().strip())
# Scores of n students
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
# No. of scores considered for alice
m = int(input().strip())
# Scores of Alice
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for i in alice:
#temp1 = sorted(alice, reverse = True)
temp = alice
print(temp)
temp2 = sorted(scores, reverse = True)
unique = []
[unique.append(item) for item in temp2 if item not in unique]
print(unique.index(i)+1)
我给爱丽丝的分数的输⼊是:
^{pr2}$
我的⽬标是先处理45,打印完排名后,再进⼊87等,,但问题是处理完45、87、23后,才打印出排名,导致答错。在
怎样才能得到正确的答案。
输⼊和输出⽰例如下:>>> n = 7
>>> scores = [100, 100, 50, 40, 40, 20, 10]
>>> m = 4
>>> alice = [5, 25, 50, 120]
相同的分数被赋予相同的等级,这样得分最⾼的⼈就可以得到第⼀名。例100是第⼀级
正确的输出是:6
4
python怎么读的2
1
但我得到了另⼀个错误的答案。(我只需要唯⼀分数的等级)
该怎么办?在

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。