题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

struct Student{
    int number;
    int score;
};

Student arr[100];

bool compare(Student x ,Student y){
    if (x.score == y.score){
        return x.number <y.number;
    }
    else{
        return x.score < y.score;
    }
}

int main(){
    int n;
    scanf("%d",&n);
    for (int i = 0;i<n;i++){
        int p,q;
        scanf("%d %d ",&p,&q);
        arr[i].number=p;
        arr[i].score=q;
    }
    sort(arr,arr+n,compare);

    for (int i = 0;i<n;i++){
        printf("%d %d\n",arr[i].number,arr[i].score);
    }
    return 0;
}

全部评论

相关推荐

那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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