lwjppz 2018-12-01 03:57 采纳率: 54.5%
浏览 355
已采纳

只用结构体要怎么做?

图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-12-01 05:53
    关注

    如果问题得到解决,请点我回答左上角的采纳和向上的箭头

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    typedef struct node
    {
        int id;
        char name[20];
        int score[4];
        node * next;
    } * List;
    
    int main()
    {
        List list = NULL;
        node * p = NULL;
        node * q = NULL;
        int n;
        scanf("%d", &n);
        node input;
        for (int i = 0; i < n; i++)
        {
            scanf("%d %s %d %d %d %d", &input.id, &input.name[0], &input.score[0], &input.score[1], &input.score[2], &input.score[3]);
            if (!list)
            {
                list = p = (node *)malloc(sizeof(node));
                p->id = input.id;
                strcpy(p->name, input.name);
                p->score[0] = input.score[0];
                p->score[1] = input.score[1];
                p->score[2] = input.score[2];
                p->score[3] = input.score[3];
                p->next = NULL;
            }
            else
            {
                p->next = (node *)malloc(sizeof(node));
                p = p->next;
                p->id = input.id;
                strcpy(p->name, input.name);
                p->score[0] = input.score[0];
                p->score[1] = input.score[1];
                p->score[2] = input.score[2];
                p->score[3] = input.score[3];
                p->next = NULL;         
            }
        }
        q = list;
        while (q->next != NULL)
        {
            p = q;
            node * min = p;
            while (p)
            {
                if ((p->score[0] + p->score[1] + p->score[2] + p->score[3]) > (min->score[0] + min->score[1] + min->score[2] + min->score[3]))
                    min = p;
                p = p->next;
            }
            if (min != q)
            {
                int tid = min->id;
                char tname[20];
                strcpy(tname, min->name);
                int tscore[4];
                memcpy(tscore, min->score, sizeof(int) * 4);
    
                min->id = q->id;
                strcpy(min->name, q->name);
                memcpy(min->score, q->score, sizeof(int) * 4);
    
                q->id = tid;
                strcpy(q->name, tname);
                memcpy(q->score, tscore, sizeof(int) * 4);
            }
            q = q->next;
        }
        p = list;
        while (p)
        {
            int sum = 0;
            int c3 = 1;
            for (int i = 0; i < 4; i++)
            {
                if (p->score[i] < 55 && i != 3) c3 = 0;
                sum += p->score[i];
            }
            if (c3 && sum >= 240)
                printf("%d %s %d %d %d %d\n",p->id, p->name, p->score[0], p->score[1], p->score[2], p->score[3]);
            p = p->next;
        }
        return 0;
    }
    

    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配