提交后显示样例的测试数据没通过,可是输出的答案都能对的上,求助求助!!!!
#include<iostream>
#include<stdlib.h>
#include<cstdio>
using namespace std;
typedef struct times {
double t;
int index;
}times;
int cmp(const void* a, const void* b) {
return (*(times*)a).t >= (*(times*)b).t ? 1 : -1;
}
int main() {
int n;
cin >> n;
times* time = (times*)malloc(sizeof(times) * n);
for (int i = 0; i < n; i++) {
cin >> time[i].t;
time[i].index = i + 1;
}
qsort(time, n, sizeof(times), cmp);
double ans = 0;
for (int i = 0; i < n; i++) {
cout << time[i].index << " ";
ans += time[i].t * (n - 1 - i);
}
ans /= n;
cout << endl;
printf("%.2lf", ans);
free(time);
return 0;
}