• 59 互评成绩 (25分)


    学生互评作业的简单规则是这样定的:每个人的作业会被k个同学评审,得到k个成绩。系统需要去掉一个最高分和一个最低分,将剩下的分数取平均,就得到这个学生的最后成绩。本题就要求你编写这个互评系统的算分模块。

    输入格式:

    输入第一行给出3个正整数N(3 << N \le 10^4104,学生总数)、k(3 \le k \le10,每份作业的评审数)、M\le 20,需要输出的学生数)。随后N行,每行给出一份作业得到的k个评审成绩(在区间[0, 100]内),其间以空格分隔。

    输出格式:

    按非递减顺序输出最后得分最高的M个成绩,保留小数点后3位。分数间有1个空格,行首尾不得有多余空格。

    输入样例:

    6 5 3
    88 90 85 99 60
    67 60 80 76 70
    90 93 96 99 99
    78 65 77 70 72
    88 88 88 88 88
    55 55 55 55 55
    

    输出样例:

    87.667 88.000 96.000
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    using namespace std;
    struct stu{
        int grades[15];//定义学生的评分的数组
        float average;//定义学生的平均分值
        float sum;//定义一个总数和
    };
    struct stu str[10005];//最大学生的数量
    bool compByGrades(int a,int b){
        return a<b;//从小到大
    }
    bool compByAverage(struct stu a,struct stu b){
        return a.average<b.average;//从小到大
    }
    int main(){
        int n,k,m;//得到学生的人数,评价的次数,最后是查看的次数
        scanf("%d%d%d",&n,&k,&m);
        int i,j;//又是老朋友计数器
        for(i=0;i<n;i++){
            for(j=0;j<k;j++){
                scanf("%d",&str[i].grades[j]);//存入每一个评价
            }
        }
        for(i=0;i<n;i++){
            sort(str[i].grades,str[i].grades+k,compByGrades);//进行排序
        }
        for(i=0;i<n;i++){
            for(j=1;j<k-1;j++){
                str[i].sum+=str[i].grades[j];//去掉最高分和最低分之后的和
            }
            str[i].average=str[i].sum/(k-2);//平均分
        }
        sort(str,str+n,compByAverage);//c++提供的快排,为什么我不自己写。。。。因为别人写的好些(好吧我还没学,我真是懒死了,我可能是一个假人)
        for(i=n-m;i<n-1;i++){
            printf("%.3f ",str[i].average);
        }
        printf("%.3f",str[i].average);//最后一个没有多余的空格
        return 0;
    }
    
  • 相关阅读:
    如何让xcode自动检查内存泄露
    Property's synthesized getter follows Cocoa naming convention for returning
    Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'Info
    iPhone开发过程中调试多次Release问题 message sent to deallocated
    委托 详解
    UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直观详解(扩展)
    代码书写规范(摸索、试行)
    简述 IOS中的LazyLoad思想
    UIImageView 详解
    20140413 科技脉搏-风平浪静,默默成长
  • 原文地址:https://www.cnblogs.com/csnd/p/16675672.html
Copyright © 2020-2023  润新知