So easy
2024-07-26 16:57:44
发布于:浙江
18阅读
0回复
0点赞
Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 100001;
int n;
double sum1 = 0, sum2 = 0;
struct stu {
double t;
int id;
} a[N];
bool cmp(stu aa, stu bb) {
return aa.t < bb.t;
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i].t;
a[i].id = i;
}
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= n; ++i)
cout << a[i].id << " ";
cout << endl;
for (int i = 1; i < n; i++) {
sum1 = sum1 + a[i].t;
sum2 = sum2 + sum1;
}
cout << fixed << setprecision(2) << sum2 * 1.0 / n;
return 0;
}
Hope you like it!
Please give a thumbs up.
这里空空如也
有帮助,赞一个