84分,关于sort
  • 板块P1104 生日
  • 楼主xyx_37jc
  • 当前回复7
  • 已保存回复7
  • 发布时间2022/8/6 00:19
  • 上次更新2023/10/27 16:48:47
查看原帖
84分,关于sort
730885
xyx_37jc楼主2022/8/6 00:19
#include<bits/stdc++.h>
using namespace std;
struct node
{
	string name;
	int y,m,d; 
}c[101];
bool operator <(node a,node b)//重载
{
	if(a.y>b.y)return true;
	if(a.y<b.y)return false;
	if(a.y==b.y)
	{
		if(a.m>b.m)return true;
		if(a.m<b.m)return false;
		if(a.m==b.m)
		{
			if(a.d>b.d)return true;
			else return false;
		}
	}
} 
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) cin>>c[i].name>>c[i].y>>c[i].m>>c[i].d;
	sort(c+1,c+n+1);
	for(i=n;i>=1;i--) cout<<c[i].name<<endl;
	return 0;
}

WA #5

2022/8/6 00:19
加载中...