Yuli


私信TA

用户名:dotcpp0689202

访问量:54

签 名:

等  级
排  名 5219
经  验 1514
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 中山大学
专  业

  自我简介:

解题思路:



注意事项:


参考代码:

#include<stdio.h>

#include<malloc.h>

typedef struct _Student

{

    char num[10];

    char name[10];

    int Chinese;

    int Maths;

    int English;

}Student;

int main()

{   

    int n = 0;

    int aver_Chinese = 0, aver_Maths = 0, aver_English = 0;

    scanf("%d", &n);

    Student* people = (Student*)malloc(sizeof(Student) * n);//people数组用于记录每位同学的信息

    int *sum= (int*)malloc(sizeof(int) * n);//sum数组用于记录总分

    for (int i = 0; i < n; i++)

    {

        scanf("%s %s %d %d %d", (people+i)->num, (people + i)->name, &(people + i)->Chinese, &(people + i)->Maths, &(people + i)->English);

        aver_Chinese += (people + i)->Chinese;

        aver_Maths += (people + i)->Maths;

        aver_English += (people + i)->English;

        *(sum + i) = (people + i)->Chinese + (people + i)->Maths + (people + i)->English;

        getchar();

    }

    aver_Chinese /= n;

    aver_Maths /= n;

    aver_English /= n;

    printf("%d %d %d\n", aver_Chinese, aver_Maths, aver_English);

    int k = 0;

    int max = *(sum + 0);

    for (int i = 0; i < n; i++)

    {

        if (*(sum + i) > max)

        {

            max = *(sum + i);

            k = i;//用k记录最大总分的下标

        }

    }

    printf("%s %s %d %d %d", (people + k)->num, (people + k)->name, (people + k)->Chinese, (people + k)->Maths, (people + k)->English);

    free(people);

    free(sum);

    return 0;

}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区