题解 | 成绩排序
成绩排序
https://www.nowcoder.com/practice/7a2f7d304d9e43b1bb2a6e72ed65bf51
#include <iostream> #include<vector> #include<algorithm> using namespace std; struct student { string name; int age; int score; student(string name,int age,int score):name(name),age(age),score(score){} bool operator < (const student& S)const { if (score != S.score)return score < S.score; else { if (name != S.name)return name < S.name; else { return age < S.age; } } } }; int main() { int n; while (cin >> n) { // 注意 while 处理多个 case vector<student>s; for(int i=0;i<n;i++){ string name; int age,score; cin>>name>>age>>score; s.push_back( student(name,age,score)); } sort(s.begin(),s.end()); for(int i=0;i<s.size();i++){ printf("%s %d %d\n",s[i].name.c_str(),s[i].age,s[i].score); } } } // 64 位输出请用 printf("%lld")