题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/7a2f7d304d9e43b1bb2a6e72ed65bf51

#include <iostream>
#include <algorithm>

using namespace std;

struct Student{
	string name;
	int age;
	int score;
};
const int MAXN = 1000 + 10;
Student student[MAXN];

bool Compare (Student x, Student y){
	if (x.score != y.score){
		return x.score < y.score;
	}
	if (x.score == y.score && x.name == y.name){
		return x.age < y.age;
	}
	if (x.score == y.score){
		return x.name < y.name; 
	} 
    return false;
}

int main () {
	int n;
	while (cin >> n){
		for (int i = 0; i < n; i++){
			cin >> student[i].name >> student[i].age >> student[i].score;
		}
		sort(student, student + n, Compare);
		for (int i = 0; i < n; i++){
			cout << student[i].name << " " << student[i].age << " " << student[i].score << endl;
		}
	}
	return 0;
}

全部评论

相关推荐

07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务