#77. 年级最高分

首先是数据的收集,即循环n次输入n个字符串。

n = int(input())
maxp = []
for i in range(n):
    s = input().split()
    maxp.append(fm(s))

就像这样,用maxp的列表来储存每个班的最高分。

然后找到每个班的最高分,这里定义了一个新函数即一直将每个班的每个人的分数与当前人的相比较。

def fm(arr):
    max = 0
    for i in arr:
        if max < int(i):
            max = int(i)
    return max

最后遍历maxp列表,找到最大值及其index即可

max = 0
index = 0
for i in maxp:
    if max < i or (max == i and index > maxp.index(i)):
        max = i
        index = maxp.index(i)

print(chr(65 + index), max)

n=int(input())
score={}
for i in range(n):
    cla=chr(i+ord("A"))
    sco=list(map(int,input().split()))
    score[cla]=sco
for i in range(n):
    for j in range(len(sco)):
             t=score[cla][j]
             s=0
            if t>s:
                 s=t
if s in score[cla]:
	print(cla)
    print(s)

这段代码首先是想用字典做,但没有一个班和班之间最大值的比较。

改好的代码如下:

n = int(input())
score = {}
for i in range(n):
    cla = chr(i+ord("A"))
    sco = (map(int,input().split()))
    max = 0
    for i in sco:
        if max < i:
            max = i
    score[cla] = max

max = 0
index = 'A'
for i in score:
    if max < score[i] or (max == score[i] and index > i):
        max = score[i]
        index = i
print(index, max)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值