简单的结构体,但是要注意这个排序还有求和重复 时的特判
AC代码附在后面
#include<bits/stdc++.h>
using namespace std;
struct Node{
string name;
int a,b,c,sum;
//语文,数学,英语
}node[1000];
bool cmp(Node a,Node b){
return a.sum>b.sum;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>node[i].name>>node[i].a>>node[i].b>>node[i].c;
node[i].sum= node[i].a+node[i].b+node[i].c;
}
int max=node[0].sum;
int count=0;
for(int i=1;i<n;i++){
if(max==node[i].sum) break;
if(max<node[i].sum) {
max=node[i].sum;
count=i;
}
}
if(count==0) {
cout<<node[0].name<<" "<<node[0].a<<" "<<node[0].b<<" "<<node[0].c<<endl;
return 0;
}
sort(node,node+n,cmp);
cout<<node[0].name<<" "<<node[0].a<<" "<<node[0].b<<" "<<node[0].c<<endl;
return 0;
}