PAT B1077 Mutual Evaluation Score Calculation (20 points)

Insert picture description here
Regarding the problem that xx.5 cannot be carried, it may be caused by the compiler. You can add 0.000005 after the output value.

avg = (g1+g2) / 2 + 0.00005;
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    
    
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i=0; i<n; i++){
    
    
		double g2 = 0;
		int num = 0;
		double arr[n];
		for(int j=0; j<n; j++){
    
    
			int g;
			scanf("%d", &g);
			if(j == 0){
    
    
				g2 = g*1.0;
			}else{
    
    
				if(g>=0 && g<=m){
    
    
					arr[num++] = g*1.0;
				}
			}
		}
		sort(arr, arr+num);
		double avg = 0;
		for(int i=1; i<num-1; i++){
    
    
			avg += arr[i];
		}
		double g1 = avg / (num-2);
		avg = (g1+g2) / 2 + 0.00005;
		printf("%.0f\n", avg);
	}
	
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45964844/article/details/114187169
Recommended