题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760
题解:
1 #include <iostream> 2 #include<vector> 3 using namespace std; 4 5 int main() { 6 int n, m; 7 cin >> n >> m; 8 for (int i = 0; i < n; i++) { 9 double G2;//定义为double便于后面计算final_score 10 cin >> G2; 11 vector<int>v; 12 for (int i = 0; i < n - 1; i++) { 13 int temp; 14 cin >> temp; 15 v.push_back(temp); 16 } 17 for (int i = 0; i < v.size(); i++) { 18 if (v[i]<0 || v[i]>m) { 19 v.erase(v.begin() + i); 20 i--;//保证删除后迭代器可以指向删除前的位置 21 } 22 } 23 int max = *v.begin(), min = *v.begin(), sum = 0; 24 for (int i = 0; i < v.size(); i++) { 25 if (max < v[i]) max = v[i]; 26 if (min > v[i]) min = v[i]; 27 sum += v[i]; 28 } 29 double G1 = (double)(sum - max - min) / (v.size() - 2);//注意求平均时要减去最高分,最低分的两个组 30 int final_score = (G1 + G2) / 2 + 0.5;//加0.5保证四舍五入 31 cout << final_score << endl; 32 } 33 return 0; 34 }
原文地址:https://www.cnblogs.com/Gzu_zb/p/9595442.html
时间: 2024-10-07 09:21:48