对小数点后第4为四舍五入
d = (d*10000+0.5)/10000.0;
PAT B 1077 互评成绩计算
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<double> ans;
for (int i = 0; i < n; i++)
{
double sum_gp = 0;
int techer, temp;
vector<int> gp;
cin >> techer;
for (int j = 0; j < n-1; j++)
{
cin >> temp;
if (temp >= 0 && temp <= m) {
gp.push_back(temp);
}
}
sort(gp.begin(), gp.end());
for (int j = 1; j <= gp.size()-2; j++)
{
sum_gp += gp[j];
}
ans.push_back((techer + (sum_gp / (gp.size() - 2)) ) / 2.0);
}
for (int i = 0; i < n; i++)
{
printf("%d
",(int) (ans[i]+0.5));
}
}