Eletronic_Monkey @ 2024-10-22 12:23:56
#include<stdio.h>
int main()
{
int n,temp=0,max;
struct student
{
char name[100];
int a;
int b;
int c;
};
scanf("%d",&n);
struct student student[n];
int sum[n];
for(int i=0;i<n;i++)
{
scanf("%s %d %d %d",&student[i].name,&student[i].a,&student[i].b,&student[i].c);
sum[i]=student[i].a+student[i].b+student[i].c;
}
max=sum[0];
for(int j=0;j<n;j++)
{
if(sum[j]>sum[0])
{
max=sum[j];
temp=j;
}
}
printf("%s %d %d %d",student[temp].name,student[temp].a,student[temp].b,student[temp].c);
return 0;
}
by cengzh @ 2024-10-22 12:40:25
这一段
for(int j=0;j<n;j++)
{
if(sum[j]>sum[0])
{
max=sum[j];
temp=j;
}
}
中
sum[j]>sum[0]
应改为
sum[j]>sum[temp]
每次比较最大值而非第一个
by Eletronic_Monkey @ 2024-10-22 12:56:05
@cengzh 太感谢了