zsj1337455772 @ 2024-12-03 18:08:18
#include<stdio.h>
#include<string.h>
typedef struct student{
char id[9];
int chinese;
int math;
int english;
int total;
}student;
int main()
{
int n,i;
scanf("%d",&n);
student students[n];
for(i=0;i<n;i++)
{
scanf("%s %d %d %d",students[i].id,&students[i].chinese,&students[i].math,&students[i].english);
students[i].total=students[i].chinese+students[i].math+students[i].english;
}
int max=students[0].total;
int maxindex=0;
for(i=1;i<n;i++)
{
if(students[i].total>max)
{
maxindex=i;
}
}
printf("%s %d %d %d",students[maxindex].id,students[maxindex].chinese,students[maxindex].math,students[maxindex].english);
}
by programmer330 @ 2024-12-03 18:23:31
@zsj1337455772
分数最大值也要更新
max=students[i].total;
加上就通过了:
#include<stdio.h>
#include<string.h>
typedef struct student{
char id[9];
int chinese;
int math;
int english;
int total;
}student;
int main()
{
int n,i;
scanf("%d",&n);
student students[n];
for(i=0;i<n;i++)
{
scanf("%s %d %d %d",students[i].id,&students[i].chinese,&students[i].math,&students[i].english);
students[i].total=students[i].chinese+students[i].math+students[i].english;
}
int max=students[0].total;
int maxindex=0;
for(i=1;i<n;i++)
{
if(students[i].total>max)
{
max=students[i].total;
maxindex=i;
}
}
printf("%s %d %d %d",students[maxindex].id,students[maxindex].chinese,students[maxindex].math,students[maxindex].english);
}
by ChasonWang @ 2024-12-03 18:24:29
忘记变max了
by ChasonWang @ 2024-12-03 18:25:26
#include<stdio.h>
#include<string.h>
typedef struct student{
char id[9];
int chinese;
int math;
int english;
int total;
}student;
int main()
{
int n,i;
scanf("%d",&n);
student students[n];
for(i=0;i<n;i++)
{
scanf("%s %d %d %d",students[i].id,&students[i].chinese,&students[i].math,&students[i].english);
students[i].total=students[i].chinese+students[i].math+students[i].english;
}
int max=students[0].total;
int maxindex=0;
for(i=1;i<n;i++)
{
if(students[i].total>max)
{
maxindex=i;
max=students[i].total;//
}
}
printf("%s %d %d %d",students[maxindex].id,students[maxindex].chinese,students[maxindex].math,students[maxindex].english);
}
by ChasonWang @ 2024-12-03 18:25:45
求关
by zsj1337455772 @ 2024-12-04 00:13:45
谢谢
by zsj1337455772 @ 2024-12-04 00:14:14
@programmer330谢谢
by zsj1337455772 @ 2024-12-04 00:14:30
@ChasonWang谢谢