//结构体重载运算符即可 #include<iostream> #include<algorithm> #include<cstring> #include<vector> using namespace std; int n; struct Stu { string name; int age,grade; bool operator<(const Stu &t) const{ if(grade!=t.grade) return grade<t.grade; else if(name!=t.name) return name<t.name; return age<t.age; } }; int main(){ cin>>n; vector<Stu> list; for(int i=0;i<n;i++){ string name; int a,g; cin>>name>>a>>g; list.push_back({name,a,g}); } sort(list.begin(),list.end()); for(auto &[k,q,v]:list){ cout<<k<<' '<<q<<' '<<v<<endl; } return 0; }