jason2024 @ 2024-05-19 22:05:45
测试点1错,求助大佬
#include<bits/stdc++.h>
using namespace std;
struct a{
string name;
int yu,shu,ying,zong;
}b[1010];
int n,c=1,d;
int main(){
cin>>n;
for(int i=1;i<=n;++i){
cin>>b[i].name>>b[i].yu>>b[i].shu>>b[i].ying;
b[i].zong=b[i].yu+b[i].shu+b[i].ying;
if(c<b[i].zong){
c=b[i].zong;
d=i;
}
}
cout<<b[d].name<<" "<<b[d].yu<<" "<<b[d].shu<<" "<<b[d].ying;
return 0;
}
by some_die_young @ 2024-05-19 22:30:57
测试点1是一个成绩信息都为0的测试点,这个时候按原顺序输出q[0]的每个信息就好了,加个特判即可以
by some_die_young @ 2024-05-19 22:32:47
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
struct node{
int all;
string s;
int a,b,c;
}q[N];
bool cmp(node a,node b){
return a.all>b.all;
}
int cnt = 0;
int main(){
int t;
cin >>t;
for(int i=0;i<t;i++){
int all;
string s;
int a,b,c;
cin >> s >> a >> b >> c;
all = a+b+c;
q[i].all = all;
q[i].s = s;
q[i].a=a;
q[i].b=b;
q[i].c=c;
cnt += all;
}
if(cnt == 0){
cout <<q[0].s<<" "<<q[0].a<<" "<<q[0].b<<" "<<q[0].c;
return 0;
}
sort(q,q+t,cmp);
cout <<q[0].s<<" "<<q[0].a<<" "<<q[0].b<<" "<<q[0].c;
return 0;
}
by jason2024 @ 2024-05-20 17:16:16
谢谢啦