题目描述
从键盘输入若干个学生的信息,每个学生信息包括学号、姓名、3门课的成绩,计算每个学生的总分,输出总分最高的学生的信息。
输入
首先输入一个整数n(1<=n<=100),表示学生人数,然后输入n行,每行包含一个学生的信息:学号(12位)、姓名(不含空格且不超过20位),以及三个整数,表示语文、数学、英语三门课成绩,数据之间用空格隔开。
输出
输出总成绩最高的学生的学号、姓名、及三门课成绩,用空格隔开。若有多个最高分,只输出第一个。
样例输入 Copy
3
541207010188 Zhangling 89 78 95
541207010189 Wangli 85 87 99
541207010190 Fangfang 85 68 76
样例输出 Copy
541207010189 Wangli 85 87 99
#include<stdio.h>
#include<stdlib.h>
typedef struct student{
char sno[13];
char sname[22];
int a;
int b;
int c;
}student;
int main(){
int t,i,maxIndex=0,ss=0,sum;
student *stu;
scanf("%d",&t);
getchar();
stu = (student *)malloc(sizeof(student)*t);
for(i=0;i<t;i++){
scanf("%s",stu[i].sno);
scanf("%s",stu[i].sname);
scanf("%d",&stu[i].a);
scanf("%d",&stu[i].b);
scanf("%d",&stu[i].c);
sum=stu[i].a+stu[i].b+stu[i].c;
if(sum>ss){
ss=sum;
maxIndex=i;
}
}
printf("%s %s %d %d %d\n",stu[maxIndex].sno,stu[maxIndex].sname,stu[maxIndex].a,stu[maxIndex].b,stu[maxIndex].c);
return 0;
}