版权声明:小简原创 https://blog.csdn.net/qq_43469554/article/details/87639930
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct Student{
string name;
int score[4];
};
int cmp(Student x, Student y)
{
if (x.score[0] != y.score[0])
{
return x.score[0] > y.score[0];
}
if (x.score[1] != y.score[1])
{
return x.score[1] > y.score[1];
}
if (x.score[2] != y.score[2])
{
return x.score[2] > y.score[2];
}
return x.score[3] > y.score[3];
}
int main()
{
Student stu[3];
for (int i = 0; i < 3; i++)
{
cin >> stu[i].name;
for (int j = 0; j < 4; j++)
{
cin >> stu[i].score[j];
}
}
sort(stu, stu + 3, cmp);
for (int i = 0; i < 3; i++)
{
cout << stu[i].name << ":";
for (int j = 0; j < 4; j++)
{
cout << stu[i].score[j] << " ";
}
cout << endl;
}
return 0;
}