64分大佬求助
  • 板块P1104 生日
  • 楼主Gohldg
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/12/26 19:10
  • 上次更新2023/10/24 06:29:59
查看原帖
64分大佬求助
757214
Gohldg楼主2022/12/26 19:10
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
struct hhh{
    string name;//名字 
    int y,m,d;//年,月,日 
    int b;//编号 
}c[100001];
bool cmp(hhh x,hhh y){
    if(x.y==y.y){//如果年份相同 
        if(x.m==y.m){//如果月份相同 
        	if(x.d==y.d){//如果日期相同 
        		return x.b<y.b;//用编号判断 
			}else
				return x.d<y.d;
		}else
			return x.m<y.m;
    }else
        return x.y<y.y;
}
int main(){
    int n;//n个人 
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i].name>>c[i].y>>c[i].m>>c[i].d;//输入名字、出生年、月、日 
		c[i].b=i;//绑编号 
	}
	sort(c+1,c+1+n,cmp);//排序 
	for(int i=1;i<=n;i++){
		cout <<c[i].name<<endl;//输出 
	}
	return 0;
}

是结构体有什么问题吗?

求助求助!QAQ

2022/12/26 19:10
加载中...