sunxiaorui @ 2024-10-06 14:58:30
#include<bits/stdc++.h>
using namespace std;
int n;
double num=0;
int a[824];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n-1;i++)
num+=a[i];
cout<<fixed<<setprecision(2)<<num/(n-2)<<endl<<max(fabs(a[2]-num/(n-2)),fabs(a[n-1]-num/(n-2)));
return 0;
}
by Focalors_HuTao @ 2024-10-06 15:19:19
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
double num=0,maxn=-112333;
double a[824];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=2;i<n;i++){
ans+=a[i];
}
printf("%.2lf ",ans/1.0/double(n-2));
for(int i=2;i<n;i++){
maxn=max(maxn,abs(ans/1.0/(n-2)-a[i]));
}
printf("%.2lf",maxn);
return 0;
}
忠告:能不秀就别秀,能写开不出错就别写一起。
a数组要开double,输出中间是空格不是换行
求关注
by Focalors_HuTao @ 2024-10-06 15:20:47
@Focalors_HuTao ``` ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
这是快速读入,不加也没啥,用法是在cin cout输入输出流中直接加在主函数下方
by sunxiaorui @ 2024-10-06 15:24:46
@Focalors_HuTao 谢谢你啦我先把另一题弄完再看一下谢谢
by heruixing @ 2024-10-13 10:22:17
???