提交时间:2019-12-09 20:35:54

运行 ID: 3005

#include<iostream> #include<algorithm> #include<iomanip> using namespace std; struct people{//结构体 int num; int time; }arr[5000]; bool cmp(people a,people b){//排序因子 return a.time<b.time;//按时间升序 } int main() { int n; int i; double time_sum=0,time_average; cin>>n; for(i=1;i<=n;i++) { cin>>arr[i].time; arr[i].num=i; } sort(arr+1,arr+1+n,cmp);//升序排序 for(i=1;i<=n;i++) { cout<<arr[i].num<<" "; if(n-i>=1) time_sum+=arr[i].time*(n-i);//计算总时间 } time_average=time_sum/n;//计算平均时间 cout<<endl; cout<<setiosflags(ios::fixed)<<setprecision(2); cout<<time_average<<endl; return 0; }