九度OJ1061

//C++ sort函数的多重排序
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef struct
{
    string name;
    int age;
    int score;
}Student;
Student stu[1001];
int cmp(Student s1,Student s2)
{
    if(s1.score<s2.score)
    return 1;
    else if(s1.score==s2.score)
    {
        if(s1.name<s2.name)
        return 1;
        else if(s1.name==s2.name)
        {
            if(s1.age<s2.age)
            return 1;
            else
            return 0;
        }
        else
        return 0;
    }
    else
    return 0;
}
int main()
{
    int n,i,j;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        cin>>stu[i].name>>stu[i].age>>stu[i].score;
        sort(stu+1,stu+n+1,cmp);
        for(i=1;i<=n;i++)
        cout<<stu[i].name<<' '<<stu[i].age<<' '<<stu[i].score<<endl;
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/wickedpriest/p/3601670.html