高质量题解|A4758.奥特曼身高问题
2026-02-06 19:02:25
发布于:北京
0阅读
0回复
0点赞
解题思路
根据题目得知,结构体中的三个元素分别为:名字、身高和日期
排序规则为先按降序排序身高,如果身高相同则升序排序日期
代码
#include <bits/stdc++.h>
using namespace std;
struct ultraman{
string name;
int height,date;
}a[1010];
bool cmp(ultraman x,ultraman y){
if(x.height != y.height){
return x.height > y.height;
}else{
return x.date < y.date;
}
}
int main(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i].name >> a[i].height >> a[i].date;
}
sort(a + 1,a + n + 1,cmp);
cout << a[1].name << " " << a[1].height << " " << a[1].date;
return 0;
}
这里空空如也








有帮助,赞一个