xuyixuan_123 @ 2024-11-15 18:59:40
代码如下
#include<bits/stdc++.h>
using namespace std;
long long n;
struct stu{
string name;
int score1=-1,score2,score3,ans;
}a[1005];
bool cmp(stu A,stu B){
if(A.ans!=B.ans)return A.ans>B.ans;
return A.ans<B.ans;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].score1>>a[i].score2>>a[i].score3;
a[i].ans=a[i].score1+a[i].score2+a[i].score3;
}
sort(a+1,a+n+1,cmp);
cout<<a[1].name<<" "<<a[1].score1<<" "<<a[1].score2<<" "<<a[1].score3;
return 0;
}
by 敢问高姓大名 @ 2024-11-15 19:25:52
17
a 0 0 0
b 0 0 0
c 0 0 0
d 0 0 0
e 0 0 0
f 0 0 0
g 0 0 0
h 0 0 0
i 0 0 0
j 0 0 0
k 0 0 0
l 0 0 0
m 0 0 0
n 0 0 0
o 0 0 0
p 0 0 0
q 0 0 0
by qianyichen20120322 @ 2024-11-17 09:34:08
@xuyixuan_123
#include <iostream>
#include <algorithm>
using namespace std;
int n;
struct stu
{
string name;
int id,a,b,c,zong;
}a[1005];
bool cmp(stu x,stu y)
{
if(x.zong!=y.zong)
return x.zong>y.zong;
return x.id<y.id;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].a>>a[i].b>>a[i].c;
a[i].zong=a[i].a+a[i].b+a[i].c;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
cout<<a[1].name<<" "<<a[1].a<<" "<<a[1].b<<" "<<a[1].c<<endl;
return 0;
}
加个id表示先后顺序 cmp第二个return 改成id
by BLUE_BANBOO @ 2024-11-17 14:22:18
bool cmp(stu A,stu B){
if(A.ans!=B.ans)return A.ans>B.ans;
return A.ans<B.ans;
}
@xuyixuan_123这个地方怎么看都有问题的吧……特别是这里
return A.ans<B.ans;
我寻思这也不是id啊,也许这就是绿名大佬的思路吗……
by BLUE_BANBOO @ 2024-11-17 14:25:29
struct Student{
string name;
int chinese,math,english;
int id,grade;
}student[N];
bool cmp(Student a,Student b){
if (a.grade != b.grade) return a.grade > b.grade;
else return a.id < b.id;
}
@xuyixuan_123这个地方要表示一下id,但如果绿名大佬有什么更好的表示方法,就当我自言自语吧