提交时间:2024-07-03 15:57:41
运行 ID: 49327
#include<iostream> #include<iomanip> using namespace std; int main() { int i,j,n,temp; cin>>n; int a[n],b[n]; for(i=0;i<n;i++){ cin>>a[i]; b[i]=i+1; } for (i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(a[i]>=a[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; temp=b[i]; b[i]=b[j]; b[j]=temp; } for (i=0;i<n;i++){ cout<<b[i]<<" "; if (i==n-1) cout<<"\n"; } double sum=0; for (i=0;i<n;i++) sum+=a[i]*(n-1-i); cout<<fixed<<setprecision(2)<<sum/n; return 0; }