题解在此
2025-05-14 21:03:28
发布于:浙江
3阅读
0回复
0点赞
小小的结构体排序:
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
string xm;
int sg,cxdnf;
}a[110];
bool cmp(node x,node y){
if (x.sg!=y.sg){
return x.sg>y.sg;
}else{
return x.cxdnf<y.cxdnf;
}
}
int main(){
int n;
cin>>n;
for (int i=1;i<=n;i++){
cin>>a[i].xm>>a[i].sg>>a[i].cxdnf;
}
sort(a+1,a+1+n,cmp);
cout<<a[1].xm<<" "<<a[1].sg<<" "<<a[1].cxdnf;
return 0;
}
这里空空如也
有帮助,赞一个