L2-015 互评成绩(排序)

题目链接

https://pintia.cn/problem-sets/994805046380707840/problems/994805062432309248

思路

我们只需要在每一个同学的评分中算出总和评分和最低最高评分即可,对于最高评分,我们定义一个 m a x w max_w maxw 初始化为 0.0 0.0 0.0 然后遍历的过程中不断取 max最低分同理,然后我们取一个平均值,放入数组或者容器中,最后排序输出前 m m m 名同学即可

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f

int n,k,m;
vector<double> V;

int main()
{
    
    
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k>>m;
	double t;
	for(int i = 1;i <= n; ++i) {
    
    
		double sum = 0.0,max_w = 0.0,min_w = 100.0;
		for(int j = 1;j <= k; ++j) {
    
    
			cin>>t;
			sum += t;
			max_w = max(max_w,t);
			min_w = min(min_w,t);
		}
		sum -= max_w + min_w;
		sum /= k - 2.0;
		V.push_back(sum);
	}
	sort(V.begin(),V.end(),greater<double>());
	cout<<fixed<<setprecision(3);
	for(int i = m - 1;i >= 0; --i)
		cout<<V[i]<<" \n"[i == 0];
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_46201544/article/details/123941870