#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student
{
string name;
int age,score;
};
bool cmp(student s1,student s2)
{
return s1.score<s2.score;
}
int main()
{
student st[4];
for(int h=0;h<4;h++)
{
cin>>st[h].name>>st[h].age>>st[h].score;
}
sort(st[0],st[4],cmp);
return 0;
}
是错误的。
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student
{
string name;
int age,score;
};
bool cmp(student s1,student s2)
{
return s1.score<s2.score;
}
int main()
{
student st[4];
for(int h=0;h<4;h++)
{
cin>>st[h].name>>st[h].age>>st[h].score;
}
sort(st,st+4,cmp);
return 0;
}
是正确的