6ms 464kb 用时比较长
#include <iostream>
#include <string>#include<algorithm>
using namespace std;
struct stuff
{
int age,sno;
string name;
};
struct rule
{
bool operator()(stuff &s1,stuff &s2)
{
if(s1.age!=s2.age)
return s1.age<s2.age;
else if (s1.sno!=s2.sno)
return s1.sno<s2.sno;
else
return s1.name<s2.name;
}
};
int main()
{
int n;
cin>>n;
stuff *s=new stuff[n];
for(int i=0;i<n;i++)
{
cin>>s[i].sno>>s[i].name>>s[i].age;
}
sort(s,s+n,rule());
if(n>3)
n=3;
for(int i=0;i<n;i++)
{
cout<<s[i].sno<<" "<<s[i].name<<" "<<s[i].age<<endl;
}
return 0;
}