文章
10
粉丝
578
获赞
16
访问
110.0k
#include<bits/stdc++.h>
using namespace std;
struct Node {
string name;
int year, score;
};
/*
按成绩从高到低排序,
如果成绩相同则按姓名字符的字典序排序,
如果姓名的字典序也相同则按照学生的年龄从小到大排序
*/
int cmp(Node n1, Node n2) {
if(n1.score != n2.score) {
return n1.score < n2.score;
} else if(n1.name != n2.name) {
return n1.name < n2.name;
} else {
return n1.year < n2.year;
}
}
int main() {
// freopen("1.txt", "r", stdin);
int n;
while(cin >> n) {
vector<Node> v;
while(n-- > 0) {
Node node;
cin >> node.name >> node.year >> node.score;
v.push_back(node);
}
sort(v.begin(), v.end(), cmp);
int size = v.size();
for(int i = 0; i < size; i++)
cout << v[i].name << " " << v[i].year << " " << v[i].score << endl;
}
}
登录后发布评论
暂无评论,来抢沙发