xyyyo 2023-03-05 19:34 采纳率: 45.5%
浏览 28
已结题

c语言简单问题,请大家解答

img

img

#include <stdio.h>

struct students 
{
    char number[10];
    int dpoint;
    int cpoint;
};


int main()
{
    int N, L, H;
    scanf_s("%d%d%d", &N, &L, &H);
    int i,j;
    int num = 0,num2=0,num3=0,num4=0,num5=0;
    struct students stu[100];
    int temp;
    for (i = 0; i < N; i++)
    {
        scanf_s("%s%d%d", stu[i].number, stu[i].dpoint, stu[i].cpoint);
    }
    int sum = stu[i].dpoint + stu[i].cpoint;
    for (i = 0; i < N; i++)
    {
        if ((stu[i].dpoint >= L) && (stu[i].cpoint >= L))
            num++;
        if ((stu[i].dpoint >= H) && (stu[i].cpoint >= H))
            num2++;
        if ((stu[i].dpoint >=H) && (stu[i].cpoint <H))
            num3++;
        if ((stu[i].cpoint <H) && (stu[i].dpoint < H)&&(stu[i].dpoint>stu[i].cpoint))
            num4++;
        if ((stu[i].dpoint >= L) && (stu[i].dpoint < H) && (stu[i].cpoint >= L) && (stu[i].cpoint < H))
            num5++;
    }
    printf("%d", num);
    
    
    for (i = 0; i < num2; i++)
    {
            int max = stu[i].dpoint + stu[i].cpoint;
            for (j = i; j < num2; j++)
            {
                if ((stu[j].dpoint + stu[j].cpoint) > max)
                    max = stu[j].cpoint + stu[j].dpoint;
            }
            if (max != (stu[i].cpoint + stu[i].dpoint))
            {
                int sum1 = stu[i].dpoint + stu[i].cpoint;
                temp = max;
                max = sum1;
                sum1 = temp;
            }
    }
    for (i = 0; i < num2; i++)
    {
        printf("%s %d %d", stu[i].number, stu[i].dpoint, stu[i].cpoint);
        printf("\n");
    }
    
    for (i = 0; i < num3; i++)
    {
        int max = stu[i].dpoint + stu[i].cpoint;
        for (j = i; j < num3; j++)
        {
            if ((stu[j].dpoint + stu[j].cpoint) > max)
                max = stu[j].cpoint + stu[j].dpoint;
        }
        if (max != (stu[i].cpoint + stu[i].dpoint))
        {
            int sum2 = stu[i].dpoint + stu[i].cpoint;
            temp = max;
            max = sum2;
            sum2 = temp;
        }
    }
    for (i = 0; i < num3; i++)
    {
        printf("%s %d %d", stu[i].number, stu[i].dpoint, stu[i].cpoint);
        printf("\n");
    }
    
    for (i = 0; i < num4; i++)
    {
        int max = stu[i].dpoint + stu[i].cpoint;
        for (j = i; j < num4; j++)
        {
            if ((stu[j].dpoint + stu[j].cpoint) > max)
                max = stu[j].cpoint + stu[j].dpoint;
        }
        if (max != (stu[i].cpoint + stu[i].dpoint))
        {
            int sum3 = stu[i].dpoint + stu[i].cpoint;
            temp = max;
            max = sum3;
            sum3 = temp;
        }
    }
    for (i = 0; i < num5; i++)
    {
        printf("%s %d %d", stu[i].number, stu[i].dpoint, stu[i].cpoint);
        printf("\n");
    }

    for (i = 0; i < num5; i++)
    {
        int max = stu[i].dpoint + stu[i].cpoint;
        for (j = i; j < num4; j++)
        {
            if ((stu[j].dpoint + stu[j].cpoint) > max)
                max = stu[j].cpoint + stu[j].dpoint;
        }
        if (max != (stu[i].cpoint + stu[i].dpoint))
        {
            int sum4 = stu[i].dpoint + stu[i].cpoint;
            temp = max;
            max = sum4;
            sum4 = temp;
        }
    }
    for (i = 0; i < num5; i++)
    {
        printf("%s %d %d", stu[i].number, stu[i].dpoint, stu[i].cpoint);
        printf("\n");
    }

}


我在输入区粘贴引例的数据时,数据无法全部正常输入,问题在哪里呢?同时希望大家帮我看一下代码其他地方有无问题,谢谢大家!

  • 写回答

2条回答 默认 最新

  • 星星来啦 2023-03-05 21:16
    关注

    你试一下这个: cin>>stu[i].number[i],>>stu[i].dpoint,>>stu[i].cpoint;
    望采纳!谢!

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月17日
  • 创建了问题 3月5日

悬赏问题

  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error