PTA 乙级 1077 互评成绩计算 (20 分) C++

 

 做的十分暴力

不多说了

直接上代码吧

python也试着写了写,总共不超过10行

自行摸索吧(嘿嘿)

C++

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 #include <cmath>
 5 using namespace std;
 6 
 7 int main() {
 8     int N = 0, M = 0;
 9     cin >> N >> M;
10     for (int i = 0; i < N; ++i) {
11         int G1 = 0;
12         cin >> G1;
13         vector<int> G2;
14         for (int j = 0; j < N - 1; ++j) {
15             int score = 0;
16             cin >> score;
17             if(score <= M && score >= 0) G2.push_back(score);
18         }
19         sort(G2.begin(), G2.end());
20         G2.pop_back();
21         G2.erase(G2.begin());
22         int sum = 0;
23         for(int j : G2) {
24             sum += j;
25         }
26         float G2_avg = sum / G2.size();
27         cout << round((G2_avg + G1) / 2) << endl;
28     }
29     return 0;
30 }

 

 

posted @ 2021-10-03 00:34  上帝的绵羊  阅读(63)  评论(0编辑  收藏  举报