GPT 3.5的题解
2024-01-20 10:04:14
发布于:浙江
57阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
struct Person {
int id;
int time;
};
bool compare(Person a, Person b) {
return a.time < b.time;
}
int main() {
int n;
cin >> n;
Person people[n];
for (int i = 0; i < n; i++) {
cin >> people[i].time;
people[i].id = i + 1;
}
sort(people, people + n, compare);
cout << people[0].id;
double totalWaitTime = 0;
for (int i = 1; i < n; i++) {
cout << " " << people[i].id;
totalWaitTime += people[i-1].time * (n - i);
}
double averageWaitTime = totalWaitTime / n;
cout << endl << fixed << setprecision(2) << averageWaitTime;
return 0;
}
这里空空如也
有帮助,赞一个