PAT B1077 互评成绩计算(C++)

PAT甲级目录 | PAT乙级目录

题目描述

B1077 互评成绩计算

解题思路

遍历每组的得分,有效分数累加到总分 sum,记录有效分数个数 cnt,同时更新最高分 max_score 和最低分 min_score。则 ave = (sum - max_score - min_score) / (cnt - 2)

易错点

  • 四舍五入输出最终得分

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int N, M;
cin >> N >> M;
for(int i = 0; i < N; i++){
int G1, G2 = 0;
int max_score = 0, min_score = M, temp, cnt = 0;
cin >> G1;
for(int j = 0; j < N - 1; j++){
cin >> temp;
if(temp >= 0 && temp <= M){
G2 += temp;
cnt++;
max_score = max(max_score, temp);
min_score = min(min_score, temp);
}
}
G2 = (G2 - max_score - min_score);
cout << (int)(1.0 * G1 + G2 / (cnt - 2) + 1) / 2 << endl;
}
return 0;
}