64分求助
  • 板块P1104 生日
  • 楼主lxl2012
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/1/27 08:27
  • 上次更新2024/1/27 08:31:20
查看原帖
64分求助
1047961
lxl2012楼主2024/1/27 08:27
#include<bits/stdc++.h>
using namespace std;
int n;
struct student{
    int years,months,days,id;
    char name[20];
};//结构体
student a[110];
bool operator >(student s1,student s2){
    if(s1.years != s2.years) return s1.years > s2.years;
    if(s1.months != s2.months) return s1.months > s2.months;
    if(s1.days != s2.days) return s1.days > s2.days;
    return s1.id > s2.id;
}//重新加载符
bool operator <(student s1,student s2){
    if(s1.years != s2.years) return s1.years < s2.years;
    if(s1.months != s2.months) return s1.months < s2.months;
    if(s1.days != s2.days) return s1.days < s2.days;
    return s1.id < s2.id;
}//重新加载符
void maopao(student *c,int n){
	for(int i = 1;i <= n - 1;i ++){
		bool b = true;
		for(int j = 1;j <= n - i + 1;j ++){
			if(*(c + j) < *(c + j - 1)){
				swap(*(c + j),*(c + j - 1));
				b = false;
			}
		}
		if(b){
			break;
		}
	}
}//指针冒泡排序
int main(){
	cin>>n;
	for(int i = 1;i <= n;i ++){
		cin>>a[i].name>>a[i].years>>a[i].months>>a[i].days;
		a[i].id = i;
	}
	maopao(&a[0],n);
	for(int i = 1;i <= n;i ++){
		cout<<a[i].name<<endl;
	}
	return 0;
}

记录

2024/1/27 08:27
加载中...