发布作者: ZHWEI
百度收录: 正在检测是否收录...
作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
stable_sort:遇到相同的元素 不调换位置
sort:反之
/*
结构体 -- 2
结构体排序
洛谷P1104
---
stable_sort:遇到相同的元素 不调换位置
sort:反之
*/
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
struct stu
{
string name;
int y, m, d;
}a[105];
bool cmp(stu x, stu y) {
if (x.y != y.y)
{
return x.y < y.y;
}
else
{
if (x.m != y.m)
{
return x.m < y.m;
}
else if (x.d != y.d)
{
return x.d < y.d;
}
}
return true;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].name >> a[i].y >> a[i].m >> a[i].d;
}
stable_sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++)
{
cout << a[i].name << endl;
}
return 0;
}
—— 评论区 ——