Alannix @ 2023-03-17 19:02:20
#include<bits/stdc++.h>
using namespace std;
struct s
{
string na;
int a,b,c,z;
}su[1000000];
bool cmp(s x,s y)
{
if(x.z==x.z)
return x.na<x.na;
return x.z>y.z;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>su[i].na>>su[i].a>>su[i].b>>su[i].c;
su[i].z=su[i].a+su[i].b+su[i].c;
}
sort(su+1,su+1+n,cmp);
cout<<su[1].na<<" "<<su[1].a<<" "<<su[1].b<<" "<<su[1].c;
return 0;
}
by qifan_maker @ 2023-03-17 19:15:27
题目说的是如果有多个总分相同的学生,输出靠前的那位,您按照名字排序了。
by 1ooper @ 2023-05-03 23:04:23
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct node{
long long x,w,s,y,ans;
string na;
}k[N];
bool cmp(node a,node z){
if(a.ans==z.ans)return a.x<z.x;
return a.ans>z.ans;
}
int main(){
long long n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>k[i].na>>k[i].w>>k[i].s>>k[i].y;
k[i].ans=k[i].w+k[i].s+k[i].y;
k[i].x=i;
}
sort(k+1,k+1+n,cmp);
cout<<k[1].na<<" "<<k[1].w<<" "<<k[1].s<<" "<<k[1].y;
}