A129378.皓仔的队伍排序
2026-07-22 12:55:52
发布于:广东
12阅读
0回复
0点赞
非常简单的结构体排序:
#include<bits/stdc++.h>
using namespace std;
struct stu { // 结构体
int year, month, day; // 表示学生的出生日期
int height; // 身高
string name; // 姓名
} st[1010];
bool cmp(stu x, stu y) { // 排序函数
if (x.height != y.height)
return x.height > y.height; // 身高高的在前
if (x.year != y.year)
return x.year < y.year; // 出生年份更早的在前
if (x.month != y.month)
return x.month < y.month; // 出生年份相同,出生月份更早的在前
return x.day < y.day; // 若出生年份、月份都相同,出生日期更早的在前
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> st[i].year >> st[i].month >> st[i].day >> st[i].height >> st[i].name; // 输入学生信息
sort(st + 1, st + 1 + n, cmp); // 排序
for (int i = 1; i <= n; i++)
cout << st[i].name << endl; // 注意:只输出学生姓名
return 0;
}
点个赞呗~
关注一下呗~
包回关的~
这里空空如也







有帮助,赞一个