结构体的运用
2023-09-15 17:41:38
发布于:上海
44阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
using namespace std;
struct Player {
int index;
int strength;
};
bool compare(Player a, Player b) {
if (a.strength == b.strength) {
return a.index < b.index;
}
return a.strength > b.strength;
}
int main() {
int n;
cin >> n;
Player players[n];
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
int strength = a + 3 * b + 9 * c;
players[i].index = i + 1;
players[i].strength = strength;
}
sort(players, players + n, compare);
for (int i = 0; i < n; i++) {
cout << players[i].index << " ";
}
cout << endl;
return 0;
}
全部评论 1
全抄的
2024-08-20 来自 浙江
0我自己写的
2024-08-22 来自 上海
0
有帮助,赞一个