题解 | #成绩排序#

成绩排序

http://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

采用的方法是用列表的方式实现的,结果在排序的时候出现了问题,调试了一下才发现
‘100’无法体现在案例中,所以转化成了整数之后进行排序,结果就没什么问题了,
所以在排序的时候,要注意字符串、整数之间还是有区别的
代码如下

while True:
    try:
        num_stu = int(input())
        flag = int(input())
        series = []
        for i in range(num_stu):
            series.append(input().split())
        if flag == 1:
            out = sorted(series,key=lambda a:int(a[1]))
            for tmp in out:
                str_out = ' '.join(tmp)
                print(str_out)
        else:
            out = sorted(series,key=lambda a:int(a[1]),reverse=True)
            for tmp in out:
                str_out = ' '.join(tmp)
                print(str_out)
    except:
        break
全部评论

相关推荐

刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务