解题思路:在读取的时候,寻找最大值和累计平均分
注意事项:
参考代码:
struct student{ char num[10]; char name[8]; int score[3]; }; void input(struct student *stu) { scanf("%s %s %d %d %d",stu->num,stu->name,&(stu->score[0]),&(stu->score[1]),&(stu->score[2])); } void print(struct student *stu) { printf("%s,%s,%d,%d,%d\n",stu->num,stu->name,stu->score[0],stu->score[1],stu->score[2]); } int main() { int n; scanf("%d",&n); struct student stu[n]; int max,index,avg1,avg2,avg3,sum; max=index=avg1=avg2=avg3=sum=0; for(int i=0;i<n;i++) { input(&stu[i]); //平均成绩 avg1 +=stu[i].score[0]; avg2 +=stu[i].score[1]; avg3 +=stu[i].score[2]; //最高分 sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]; if(max<sum) { max=sum; index=i; } } printf("%d %d %d\n",avg1/n,avg2/n,avg3/n); printf("%s %s %d %d %d",stu[index].num,stu[index].name,stu[index].score[0],stu[index].score[1],stu[index].score[2]); }
0.0分
0 人评分