LPY0204 @ 2022-02-19 16:49:11
#include<stdio.h>
struct student{
char name[9];
int score[3];
}s[1000];
int main(){
int n,i,j,max=0,sum=0,k=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s",s[i].name);
for(j=0;j<3;j++){
scanf("%d",&s[i].score[j]);
sum+=s[i].score[j];
}
if(sum>max)
k=i;//k用来记录最大值下标
sum=0;
}
printf("%s ",s[k].name);
for(j=0;j<3;j++){
printf("%d ",s[k].score[j]);
}
}
by summer2020 @ 2022-02-19 17:01:46
max值没更新 贴上代码:
#include<stdio.h>
struct student{
char name[9];
int score[3];
}s[1000];
int main()
{
int n,i,j,max=0,sum=0,k=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",s[i].name);
for(j=0;j<3;j++)
{
scanf("%d",&s[i].score[j]);
sum+=s[i].score[j];
}
if(sum>max)
{
k=i;
max=sum;
}
sum=0;
}
printf("%s ",s[k].name);
for(j=0;j<3;j++){
printf("%d ",s[k].score[j]);
}
}