PAT Basic 1077. 互评成绩计算

发布时间 2023-04-09 10:34:24作者: 十豆加日月

PAT Basic 1077. 互评成绩计算

1. 题目描述:

在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为 \(G_1\);老师给这个组的评分记为 \(G_2\)。该组得分为 \((G_1+G_2)/2\),最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。

2. 输入格式:

输入第一行给出两个正整数 \(N\)\(> 3\))和 \(M\),分别是分组数和满分,均不超过 100。随后 \(N\) 行,每行给出该组得到的 \(N\) 个分数(均保证为整型范围内的整数),其中第 1 个是老师给出的评分,后面 \(N−1\) 个是其他组给的评分。合法的输入应该是 \([0,M]\) 区间内的整数,若不在合法区间内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有 3 个来自同学的合法评分。

3. 输出格式:

为每个组输出其最终得分。每个得分占一行。

4. 输入样例:

6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29

5. 输出样例:

42
33
41
31
37
39

6. 性能要求:

Code Size Limit
16 KB
Time Limit
400 ms
Memory Limit
64 MB

思路:

除草题,按照题意编写即可。

My Code:

#include <stdio.h>

int main(void)
{
    int groupCount = 0, maxGrade = 0;
    int i=0; // iterator
    //double tempGrade = 0.0;
    int validCount = 0;
    int tempRes = 0;
    //double tempSum = 0.0;
    int teacherGrade = 0, tempGrade = 0;
    int j=0; // iterator
    int tempSum = 0;
    int tempMax = 0, tempMin = 0;
    
    scanf("%d%d", &groupCount, &maxGrade);
    for(i=0; i<groupCount; ++i)
    {
        tempSum = 0;
        validCount = 0;
        tempMax = -1;
        tempMin = maxGrade+1;
        
        for(j=0; j<groupCount; ++j)
        {
            scanf("%d", &tempGrade);
            if(!j)
            {
                teacherGrade = tempGrade; // teacherGrade is always valid
            }
            else
            {
                if(tempGrade>=0 && tempGrade <= maxGrade) // if valid
                {
                    if(tempGrade > tempMax)
                        tempMax = tempGrade;
                    if(tempGrade < tempMin)
                        tempMin = tempGrade;
                    tempSum += tempGrade;
                    ++validCount;
                }
            }
        }
        tempSum -= tempMax;
        tempSum -= tempMin;
        validCount -= 2;
        
        //printf("teacherGrade: %d, tempSum: %d\n", teacherGrade, tempSum);
        tempRes = teacherGrade*0.5 + tempSum*0.5/validCount + 0.5;
        printf("%d\n", tempRes);
    }
    
    return 0;
}