Kingson999 @ 2024-07-11 19:17:39
#include<bits/stdc++.h>
using namespace std;
struct P5740{
string a;
int b,c,d;
int cmp=0;
}tmp[114514];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>tmp[i].a>>tmp[i].b>>tmp[i].c>>tmp[i].d;
tmp[i].cmp=tmp[i].b+tmp[i].c+tmp[i].d;
}
int max=0;
int maxi=0;
for(int i=1;i<=n;i++){
if(tmp[i].cmp>max){
max=tmp[i].cmp;
maxi=i;
}
}
cout<<tmp[maxi].a<<' '<<tmp[maxi].b<<' '<<tmp[maxi].c<<' '<<tmp[maxi].d;
return 0;
}
第一个样例不过 求调
by xuruizhe0711 @ 2024-07-15 14:54:37
#include<bits/stdc++.h>
using namespace std;
struct student{
string xm;
int name;
int china;
int math;
int english;
int score;
}a[1005];
bool cmp(student a,student b){
if(a.score>b.score){
return 1;
}
if(a.score==b.score&&a.name<b.name){
return 1;
}
return 0;
}
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].xm>>a[i].china>>a[i].math>>a[i].english;
a[i].score=a[i].china+a[i].math+a[i].english;
a[i].name=i;
}
sort(a+1,a+n+1,cmp);
cout<<a[1].xm<<" "<<a[1].china<<" "<<a[1].math<<" "<<a[1].english<<endl;
return 0;
}