题解 | #成绩排序#

成绩排序

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

#include <iostream>
#include<algorithm>
typedef struct student{
    int snum;
    int score;
};
using namespace std;
bool Compare(student a,student b){
    if(a.score==b.score){
        return a.snum<b.snum;
    }else {
        return a.score<b.score;
        }
}
int main()
{   int n;
    while(scanf("%d",&n)!=EOF){
        student stu[n];
        for(int i=0;i<n;i++){
        scanf("%d %d",&stu[i].snum,&stu[i].score);
      }

      sort(stu,stu+n,Compare);
      for(int j=0;j<n;j++){
        printf("%d %d\n",stu[j].snum,stu[j].score);
      }

    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 13:15
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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