include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
struct Student {//学生结构,记录学生数据
string name;
int age;
int grades;
};
Student stu[1000];
bool strBiger(string s1, string s2) {//判断字符串大小
int len = s1.size() > s2.size() ? s2.size() : s1.size();
for (int i = 0; i < len; i++) {
if (s1[i] > s2[i])
return 1;
if (s1[i] < s2[i])
return 0;
}
return s1.size() > s2.size() ? 1 : 0;
}
// 测试时候发现两人成绩相同,姓名相同时,得按年龄排,因为前面都写好了,
// 就再前面加一个函数判断姓名是否一样再跳转比较年龄
bool sample(string s1, string s2) {
if (s1.size() == s2.size()) {
for (int i = 0; i < s1.size(); i++) {
if (s1[i] != s2[i])
return 0;
}
return 1;
}
return 0;
}
bool stuBiger(Student stu1, Student stu2) {//判断两学生类大小
if (stu1.grades > stu2.grades)
return 1;
if (stu1.grades < stu2.grades)
return 0;
if (sample(stu1.name, stu2.name)) {
if (stu1.age > stu2.age)
return 1;
return 0;
}
return strBiger(stu1.name, stu2.name) ? 1 : 0;
}
void Sort(Student *stu, int n) {// 对学生类进行排序
for (int i = n-1; i > 0; i–) {
for (int j = 0; j < i; j) {
if (stuBiger(stu[j], stu[j + 1]))
{
Student tmp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = tmp;
}
}
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i) {
cin >> stu[i].name >> stu[i].age >> stu[i].grades;
}
Sort(stu, n);
for (int i = 0; i < n; i++) {
cout << stu[i].name<<” ” << stu[i].age<<” ” << stu[i].grades;
cout << endl;
}
}