1180: Achievement Statistics (Structured Topics)

1180: Achievement Statistics (Structured Topics)

Topic Description
Input the information of several students from the keyboard, each student information includes student number, name, grades of 3 courses, calculate the total score of each student, and output the information of the student with the highest total score.
Input
First enter an integer n (1<=n<=100), indicating the number of students, then input n lines, each line contains the information of one student: student number (12 digits), name (without spaces and no more than 20 digits) ), and three integers, indicating the results of three courses of Chinese, mathematics, and English. The data are separated by spaces.
Output
Output the student number, name, and grades of three courses of the student with the highest total grades, separated by spaces. If there are multiple highest scores, only the first one will be output.
Sample input Copy
3
541207010188 Zhangling 89 78 95
541207010189 Wangli 85 87 99
541207010190 Fangfang 85 68 76
Sample output Copy
541207010189 Wangli 85 87 99

Source/Classification

#include<stdio.h>

typedef struct student{
    
    
    char id[13];
    char name[22];
    int c;
    int m;
    int e;
}student;

int main(){
    
    
    int n;
    student stu,max;
    scanf("%d",&n);

    max.c=0;
    max.m=0;
    max.e=-1;
    while(n--){
    
    
        scanf("%s %s %d %d %d",stu.id,stu.name,&stu.c,&stu.m,&stu.e);
        if(stu.c+stu.m+stu.e>max.c+max.m+max.e) {
    
    
            max=stu;
        }
    }

    printf("%s %s %d %d %d\n",max.id,max.name,max.c,max.m,max.e);
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44500344/article/details/108148840