PTA (Basic Level) 1077. Peer assessment score is calculated

Computer Course in Zhejiang, there are often cross-score group report this link. A group stage to introduce their work, other groups in the audience for their performance scores. This last group of mutual evaluation score is calculated by: the score of all other groups, removing a highest and lowest points, the remaining fraction of averaged points referred to as G . 1; Teacher Rating referred to as the group G 2 . This score group ( G 1+ G 2) / 2, the final result after the decimal points are rounded. This question requires you to write a program to help teachers calculated for each group of peer assessment scores.

Input formats:

Input of the first line gives two positive integers N (>. 3) and M , respectively, and the number of packets out, not more than 100. Then N rows, each row of the group obtained are given N th fraction (Guarantee integer within the range of an integer), the first of which is a teacher ratings given, followed by N -1 is the number of scores to other groups. Should be valid input [, 0 M ] integer in the interval, if not in the valid range, the score shall be ignored. Subject teachers to ensure that ratings are legitimate, and each group will have at least three legitimate scoring from classmates.

Output formats:

The final score for each group which is output. Each score per line.

Sample input:
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
Sample output:
42
33
41
31
37
39
Thinking
  • After sorting excluding highest and lowest error-prone point is not calculated each time a new line emptyvector
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    std::vector<int> v;

    int tmp;
    for(int i=0;i<n;i++)
    {
        v.clear();   //记得每计算新的一行要清空vector
        for(int j=0;j<n;j++)
        {
            cin >> tmp;
            if(tmp>=0 && tmp<=m)
                v.push_back(tmp);
        }

        // 读完一行了
        sort(v.begin()+1,v.end());   //不包括老师
        //for(int j=0;j<v.size();j++) cout << v[j] << " "; cout<<endl;
        double ans = 0.0;
        for(int j=2;j<v.size()-1;j++)
            ans += v[j];
        //cout << ans << endl;
        ans /= (v.size() - 3);
        ans = (v[0] + ans) / 2.0;
        cout << round(ans) << endl;
    }
    return 0;
}
Quote

https://pintia.cn/problem-sets/994805260223102976/problems/994805262303477760

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11614267.html