LYQ_666 @ 2024-07-12 21:47:12
#include<bits/stdc++.h>
using namespace std;
struct LYQ
{
string name;
int a1,a2,a3,a4;
}E[1001];
bool cmp(LYQ a,LYQ b)
{
a.a4>b.a4;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>E[i].name>>E[i].a1>>E[i].a2>>E[i].a3;
E[i].a4=E[i].a1+E[i].a2+E[i].a3;
}
sort(E,E+n,cmp);
cout<<E[n-1].name<<" "<<E[n-1].a1<<" "<<E[n-1].a2<<" "<<E[n-1].a3;
return 0;
}
by Maisie586_ @ 2024-07-12 21:48:39
@LYQ_666 求关
#include <bits/stdc++.h>
using namespace std;
struct abc{
string name;
int all_subject,chinese,math,english;
int id;
}a[11100];
bool cmp(abc a,abc b)
{
if(a.all_subject==b.all_subject){
return a.id<b.id;
}
return a.all_subject>b.all_subject;
}
int main() {
int t1,t2,t3;
int n;
string s;
cin >> n;
for(int i=1;i<=n;i++){
cin >>s>> t1 >> t2 >> t3;
a[i].name = s;
a[i].chinese = t1;
a[i].math = t2;
a[i].english = t3;
a[i].all_subject=t1+t2+t3;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
cout << a[1].name << " "<<a[1].chinese;
cout << " " << a[1].math << " " << a[1].english;
}
by LYQ_666 @ 2024-07-12 21:50:15
@Maisie586_ OK