文章

93

粉丝

56

获赞

289

访问

46.1k

头像
成绩排序 - 华科 题解:暴力
P1404 华中科技大学
发布于2025年3月15日 12:14
阅读数 459

#include <bits/stdc++.h>
using namespace std;

struct student
{
    string str;
    int score;
    int age;
}stu[1005];

bool cmp(student a,student b)
{
    if(a.score!=b.score)return a.score<b.score;
    else if(a.str!=b.str)return a.str<b.str;
    else return a.age<b.age;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>stu[i].str>>stu[i].age>>stu[i].score;
    }
    stable_sort(stu,stu+n,cmp);
    for(int i=0;i<n;i++)
    {
        cout<<stu[i].str<<" "<<stu[i].age<<" "<<stu[i].score<<endl;
    }
    return 0;   &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发