题解 | #成绩排序#

成绩排序

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



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

using namespace std;

struct Student {
    int number;
    int score;
};

const int MaxSize = 100 + 10;

Student arr[MaxSize];

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 = 0;
    //while(scanf("%d",&n)!=EOF)
    scanf("%d",&n);
    for(int i = 0; i<n;i++){
        scanf("%d%d",&arr[i].number,&arr[i].score);
    }
    sort(arr, arr + n , Compare);
    for(int i = 0; i<n ;i++){
        cout << arr[i].number << " " << arr[i].score << endl;
    }
    return 0;
    
}
//直接从结构体定义中定义大小,此为默认比较方法,不需要compare函数。
struct Student {
    int number;
    int score;
    bool operator< (Student student) const {
        if (score == student.score){
            return number < student.number;
        }else {
            return score < student.score;
        }
    }
}
全部评论

相关推荐

仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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