#include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef struct student { string name; int age; int grade; } student; bool cmp(student s1, student s2) { if (s1.grade != s2.grade)return s1.grade < s2.grade; if (s1.name != s2.name)return s1.name < s2.name; return s1.age < s2.age; } int main() { int n; cin >> n; student* s = new student[n]; for (int i = 0; i < n; i++)cin >> s[i].name >> s[i].age >> s[i].grade; sort(s, s + n, cmp); for (int i = 0; i < n;i++)cout << s[i].name << " " << s[i].age << " " << s[i].grade << endl; return 0; }
sort()函数和string类型的比较