#include<iostream>
#include<string>
using namespace std;
struct Subject
{
int math;
int english;
int chinese;
};
struct Student
{
int age;
string name;
Subject score;
};
void bubble(Student b[], int len)
{
for (int i=0; i < len; i++)
{
for (int j=0; j < len - i - 1; j++)
{
if (b[j].score .chinese > b[j + 1].score .chinese )
{
Student temp;
b[j] = temp;
b[j] = b[j + 1];
b[j + 1] = temp;
}
}
}
}
void print(Student s[],int k)
{
cout << "根据语文成绩排序后的学生排名:" << endl;
for (int i=0; i < k; i++)
{
cout << "姓名:" << s[i].name << " 年龄:" << s[i].age << " 语文 数学 英语成绩:" << s[i].score.chinese << " " << s[i].score.math << " " << s[i].score.english << endl;
}
}
int main()
{
Student a[3] =
{
{18,"张三",{80,90,100}},
{19, "李四", {99, 99, 99}},
{20,"王五",{77,77,77}},
};
int len = sizeof(a)/sizeof(a[0]);
bubble(a, len);
print(a, len);
}