讨论 / 一遍AC!
fushh7 2020-04-12 09:48:57
点我顶贴 收藏 删除
#include<iostream>

#include<stdio.h>

#include<algorithm>

using namespace std;

typedef struct

{

int NO;

int time;

}ren;

bool comp(const ren &left,const ren &right)

{

if(left.time<right.time)

return true;

if(left.time==right.time&&left.NO<right.NO)

return true;

return false;

}

ren people[1000];

int main()

{

int n;

cin>>n;

for(int i=0;i<n;i++)

{

cin>>people[i].time;

people[i].NO=i+1;

}

sort(people,people+n,comp);

long long total=0;

long long sum=0;

for(int i=0;i<n;i++)

{

cout<<people[i].NO<<' ';

total+=sum;

sum+=people[i].time;

}

printf("\n%.2f",(double)total/n);

}

查看更多回复
提交回复