1077 互评成绩计算 (20 分)

【我的代码】

//1077 互评成绩计算 (20 分)
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    double G1, temp1, G2;
    double G[N];
    int count = 0;//有效成绩 
    for(int i = 0; i < N; i++){
        int x = 0;
        for(int i = 0; i < N; i++){
            cin>>temp1;
            //判断合法非法 
            if(temp1 >= 0 && temp1 <= M){
                G[x++] = temp1;
            }
        }
        G2 = G[0];//老师评分
        sort(G+1 ,G+x);
        temp1 = 0;
        for(int i = 2; i < x-1; i++){
            temp1 += G[i];
            count = i - 1;
        }
        cout<<round(((temp1 / count) + G2) / 2)<<endl;
    }
    return 0;
}

【思路】

很常规的题目,注意记住关于四舍五入,C++有封装好的库函数可以直接调用。

收藏 打印