神秘玄学的stable_sort

Link

https://www.luogu.org/problemnew/solution/P1104

Problem

神秘玄学的stable_sort_第1张图片
神秘玄学的stable_sort_第2张图片

AC code

#include
#include
#include
#include
#include
#include
typedef long long ll;
using namespace std;
typedef struct a{
string s;
int year,month,day;
}N;
bool cmp(N a,N b){
if(a.year==b.year&&a.month==b.month)return a.day<=b.day;
if(a.year == b.year)return a.month < b.month;

return a.year < b.year;
}
int y,m,d;
int main(){
int n;
cin >> n;
N A[505];
for(int i = 1;i <= n;i++){
	cin >> A[i].s >> A[i].year >> A[i].month>>A[i].day;
	}
stable_sort(A+1,A+1+n,cmp);
for(int i = 1;i <= n;i++)cout << A[i].s << endl;

return 0;
}

comments

exchange the sort to stable_sort , it can accept ???

你可能感兴趣的:(题解,结构体排序,洛谷黄题,入门级别,结构体排序)