题解 | 成绩排序

成绩排序

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

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
struct student
{
    int num;
    double score;
};
bool px(const student &std1,const student &std2)
{
    if(std1.score==std2.score)
    return std1.num<std2.num;
    else
    return std1.score<std2.score;
}
int main() {
    int n;
    cin>>n;
    vector<student>std(n);
    for(int i=0;i<n;i++)
    {
        cin>>std[i].num>>std[i].score;
    }
    sort(std.begin(),std.end(),px);
    for(int i=0;i<n;i++)
    {
        cout<<std[i].num<<" "<<std[i].score<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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