#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct Student {
string name, id;
int grade = 0;
}stu[32];
int cmp_stu(const void* e1, const void* e2)
{
return (*(Student*)e2).grade - (*(Student*)e1).grade;
}
bool cmp(Student& stu1, Student& stu2)
{
return stu1.grade > stu2.grade;
}
int main()
{
int n;
while (cin >> n)
{
for (int i = 0;i < n;i++) {
cin >> stu[i].name >> stu[i].id >> stu[i].grade;
}
//qsort(stu, n, sizeof(stu[0]), cmp_stu);
sort(&stu[0], &stu[n] , cmp);
for(int i = 0;i < n;i ++)
cout << stu[i].name << " " << stu[i].id << " " << stu[i].grade << endl;
//cout << stu[0].name << " " << stu[0].id << " " << stu[0].grade << endl;
//cout << stu[n - 1].name << " " << stu[n - 1].id << " " << stu[n - 1].grade << endl;
cout << endl;
}
return 0;
}
结构体sort排序
最新推荐文章于 2024-08-24 14:01:36 发布