社区讨论
help me,必关
P1104生日参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mk81mgv4
- 此快照首次捕获于
- 2026/01/10 16:28 2 个月前
- 此快照最后确认于
- 2026/01/13 13:25 2 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int n;
struct student{
string name;
int id,bri,th,day; // bri=年,th=月,day=日
}s[101];
// 排序规则:按出生日期从小到大,同生日按ID从小到大
bool cmp(student x, student y){
if(x.bri!=y.bri) return x.bri<y.bri; // 年份小的在前
if(x.th!=y.th) return x.th<y.th; // 月份小的在前
if(x.day!=y.day) return x.day<y.day; // 日期小的在前
return x.id<y.id; // 同生日,ID小的在前
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i].name>>s[i].bri>>s[i].th>>s[i].day;
s[i].id=i; // 录入顺序作为ID
}
sort(s+1,s+1+n,cmp); // 按正确规则排序
for(int i=1;i<=n;i++){ // 正向输出排序结果
cout<<s[i].name<<endl;
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...