A8 W2 带注释 没看出来错在哪,请求指点一下

#include <stdio.h>

typedef struct
{
    char name[20];    //姓名
    int final;    //期末成绩
    int asse;    //评定成绩
    char leader;
    char western;    //是否西部
    int paper;    //发表论文
    int salary;    //奖金
}student;


int salary(student p){    //计算奖金
    int average = p.final;
    int money = 0;

    if(average > 80 && p.paper >= 1)
        money = money + 8000;
    if(average > 85 && p.asse >80)
        money = money + 4000;
    if(average > 90)
        money = money + 2000;
    if(average > 85 && p.western =='Y')
        money = money + 1000;
    if(p.asse > 80 && p.leader == 'Y')
        money = money + 850;
    return money;
}


int main(int argc, char const *argv[])
{   
    //录入学生信息

    int N;    //学生总数
    scanf("%d",&N);
    student temp;
    student a[N];
    for (int i = 0; i < N; i++)    //输入信息
    {
        scanf("%s %d %d %c %c %d ",&a[i].name,&a[i].final,&a[i].asse,&a[i].leader,&a[i].western,&a[i].paper);
        a[i].salary = salary(a[i]);
    }
    
    //求最多奖学金的学生
    for (int i = 0; i + 1 < N; i++)
    {
        if (a[i].salary>a[i+1].salary){
            temp = a[i];
            a[i] = a[i+1];
            a[i+1] = temp; 
        }
    }
    printf("%s\n%d\n",a[N-1].name,a[N-1].salary);

    //输出总奖学金
    int all = 0;
    for (int i = 0; i < N; i++)
    {
        all = all + a[i].salary;
    }
    printf("%d\n",all );
    return 0;
    
}

1 条评论

  • @ 2018-07-12 17:31:50

    仔细审题发现忽略了“如果奖学金相同,输出出现最早的学生的姓名”这个条件。(错误的地方出现在第二个和倒数第二个)
    更改了排序方法,解决,供参考。

    #include <stdio.h>
    
    typedef struct
    {
        char name[20];    //姓名
        int final;    //期末成绩
        int asse;    //评定成绩
        char leader;
        char western;    //是否西部
        int paper;    //发表论文
        int salary;    //奖金
    }student;
    
    
    int salary(student p){    //计算奖金
        int average = p.final;
        int money = 0;
    
        if(average > 80 && p.paper >= 1)
            money = money + 8000;
        if(average > 85 && p.asse >80)
            money = money + 4000;
        if(average > 90)
            money = money + 2000;
        if(average > 85 && p.western =='Y')
            money = money + 1000;
        if(p.asse > 80 && p.leader == 'Y')
            money = money + 850;
        return money;
    }
    
    
    int main(int argc, char const *argv[])
    {   
        //录入学生信息
    
        int N;    //学生总数
        scanf("%d",&N);
        student temp;
        student a[N];
        for (int i = 0; i < N; i++)    //输入信息
        {
            scanf("%s %d %d %c %c %d ",&a[i].name,&a[i].final,&a[i].asse,&a[i].leader,&a[i].western,&a[i].paper);
            a[i].salary = salary(a[i]);
        }
        
        //求最多奖学金的学生
        for(int i = 1;i < N;i++){
            if(a[i].salary > a[0].salary){
                temp = a[i];
                a[i] = a[0];
                a[0] = temp;
            }
        }
        printf("%s\n%d\n",a[0].name,a[0].salary);
    
        //输出总奖学金
        int all = 0;
        for (int i = 0; i < N; i++)
        {
            all = all + a[i].salary;
        }
        printf("%d\n",all );
        return 0;
    }
    
  • 1

信息

ID
1001
难度
5
分类
模拟 点击显示
标签
递交数
31254
已通过
10568
通过率
34%
上传者