成绩排序

成绩排序_牛客网

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b?tpId=37&tqId=21291&rp=0&ru=/ta/huawei&qru=/ta/huawei/question-ranking

while True:
    try:
        num=int(input())
        m=int(input())
        table=[]
        for each in range(num):
            tableLine=input().split(' ')
            name,score=tableLine[0],int(tableLine[1])
            table.append((name,score))
        if m==0:
            newTable=sorted(table,key=lambda x:x[1],reverse=True)
        else:
            newTable=sorted(table,key=lambda x:x[1])
        for each in newTable:
            print(each[0]+' '+str(each[1]))
    except:
        break
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int num,n,score;
    string name;
    while(cin >> num >> n){
        vector<string> b[101];
        for(int i=0;i<num;i++){
            cin >> name >> score;
            b[score].push_back(name);
        }
        if(n==0){
            for(int i=100;i>=0;i--){
                for(int j=0;j<b[i].size();j++)
                    cout << b[i][j] << " " << i << endl;
            }
        }
        else{
            for(int i=0;i<101;i++){
                for(int j=0;j<b[i].size();j++)
                    cout << b[i][j] << " " << i << endl;
            }
        }
    }
    return 0;
}


全部评论
n= int(input()) p=int(input()) if p==0: p=True else: p=False d={} for i in range(n): s=list(input().split(" ")) d[s[0]]=int(s[1]) d1=sorted(d.items(),key=lambda item:item[1],reverse=p) for j in d1: print(j[0]+' '+str(j[1])) 为啥这个python会通不过呢。思想差不多啊。while true 和try——break都有
点赞 回复 分享
发布于 2021-09-17 20:29
机智啊
点赞 回复 分享
发布于 2021-03-23 21:16

相关推荐

想玩飞盘的菠萝蜜在春...:上交✌🏻也拒?
点赞 评论 收藏
分享
评论
7
1
分享

创作者周榜

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