C_vegetable @ 2021-01-15 16:52:29
#include <stdio.h>
#include <string.h>
struct stu
{
char name[9];
int chinese;
int math;
int english;
int average;
};
int main()
{
struct stu grade[1000];
int n,i,max,i1;
scanf("%d",&n);getchar();
for(i=0;i<n;i++)
{
scanf("%s",grade[i].name);
scanf("%d%d%d",&grade[i].chinese,&grade[i].math,&grade[i].english);
getchar();
grade[i].average=(grade[i].chinese+grade[i].math+grade[i].english);
}
max=grade[0].average;
for(i=1;i<n;i++)
if(grade[i].average>max)
{
max=grade[i].average;
i1=i;
}
printf("%s %d %d %d",grade[i1].name,grade[i1].chinese,grade[i1].math,grade[i1].english);
}
by CGDGAD @ 2021-01-15 16:58:46
@C_vegetable 给i1一个初值亲测可以通过
by CGDGAD @ 2021-01-15 16:59:33
int n,i,max,i1
\ \ \textbf{=0} ;
by 永动姬 @ 2021-01-15 17:02:59
@C_vegetable
给你附上没有Re的代码:
#include<bits/stdc++.h>
using namespace std;
struct xm{
string s;
int x;
int y;
int z;
}a[1004];
int b[1004];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i].s>>a[i].x>>a[i].y>>a[i].z;
b[i]=a[i].x+a[i].y+a[i].z;
}
for(int i=0;i<n;i++){
int c=0;
if(b[c]>=b[i]){
cout<<a[c].s<<' '<<a[c].x<<' '<<a[c].y<<' '<<a[c].z;
break;
}
else{
c++;
}
}
return 0;
}
by C_vegetable @ 2021-01-16 09:11:02
@NSObject !哦对呀!大师,我悟了 感谢感谢感谢
by C_vegetable @ 2021-01-16 09:11:42
@羽翼喵呀 好的好的,感谢dalao!