蒟蒻求解惑QAQ
查看原帖
蒟蒻求解惑QAQ
1027079
AndrewJTL楼主2023/7/16 20:03
#include<bits/stdc++.h>
using namespace std; 
double P(int X[],int m){
	int s=0,i;
	sort(X,X+m);
	for (i=1;i<m-1;i++) s=s+X[i];
	cout<<"s="<<s<<endl;
	return s/(1.0*(m-2));
}
	double a;
int main()
{
	int m,n,i,j;

	cin>>n>>m;
	int X[m];
	for (i=0;i<n;i++){
		for(j=0;j<m;j++) cin>>X[j];
		if (a<P(X,m)) a=P(X,m);
		cout<<"P(X,m)="<<P(X,m)<<endl;
	}
	
	cout<<fixed<<setprecision(2)<<a;
	return 0;
}

这是本蒟蒻在做P5738 【深基7.例4】歌唱比赛的时候的AC代码(含有部分自我检查点)然后在输出结果的时候出现了一些奇怪的事情(数据用的样例)

7 6
4 7 2 6 10 7
s=24
s=24
s=24
P(X,m)=6
0 5 0 10 3 10
s=18
s=18
P(X,m)=4.5
2 6 8 4 3 6
s=19
s=19
P(X,m)=4.75
6 3 6 7 5 8
s=24
s=24
P(X,m)=6
5 9 3 3 8 1
s=19
s=19
P(X,m)=4.75
5 9 9 3 2 0
s=19
s=19
P(X,m)=4.75
5 8 0 4 1 10
s=18
s=18
P(X,m)=4.5
6.00

有没有大佬解答一下为啥s会输出两或三次。。。

2023/7/16 20:03
加载中...