PAT Basic 1077 mutual evaluation score calculation (20 minutes)

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 this group It is  G 2 . The group score  (final results retained after integer division rounding. This problem 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 set is given obtained  of N points (Guarantee integer within the range of an integer), the first of which is a teacher ratings given, later  N - 1 groups to the other score. The input should be a legal  integer in the [range, if not within the legal range, the fraction 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


Note the use of floating-point calculations, and finally rounding
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
void deal(vector<double> v){
    double t_grade=v[0];double avg=0;
    v.erase (v.begin ());
    sort(v.begin(),v.end());
    for(int i=1;i<v.size()-1;i++) avg+=v[i];
    avg/=(v.size()-2);
    printf("%d\n",(int)((t_grade+avg)/2+0.5));
}
int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<double>> v;
    string f_l;getline(cin,f_l);
    for(int i=0;i<N;i++){
        vector<double> tmp;
        string tmp_str;
        getline(cin,tmp_str);
        stringstream ss;
        ss<<tmp_str;
        double tmp_i;
        while(ss>>tmp_i){
            if(tmp_i>=0&&tmp_i<=M) tmp.push_back(tmp_i);
        }
        v.push_back(tmp);
    }
    for(int i=0;i<v.size();i++)
        deal(v[i]);
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11701684.html
Recommended