struct utilization
2024-04-23 22:26:26
发布于:广东
24阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 定义一个结构体来存储玩家信息
struct Player {
int index; // 玩家序号
int oneStar; // 1星英雄数量
int twoStar; // 2星英雄数量
int threeStar; // 3星英雄数量
int strength; // 阵容强度
};
// 计算阵容强度
int calculateStrength(int oneStar, int twoStar, int threeStar) {
return oneStar + twoStar * 3 + threeStar * 9;
}
// 按照阵容强度排序的比较函数
bool comparePlayers(const Player &a, const Player &b) {
if (a.strength != b.strength) {
return a.strength > b.strength; // 强度大的在前
} else {
return a.index < b.index; // 强度相同,序号小的在前
}
}
int main() {
int n;
cin >> n;
vector<Player> players(n);
// 输入玩家信息并计算阵容强度
for (int i = 0; i < n; ++i) {
players[i].index = i + 1;
cin >> players[i].oneStar >> players[i].twoStar >> players[i].threeStar;
players[i].strength = calculateStrength(players[i].oneStar, players[i].twoStar, players[i].threeStar);
}
// 按照阵容强度和序号排序玩家
sort(players.begin(), players.end(), comparePlayers);
// 输出排序后的玩家序号
for (const auto &player : players) {
cout << player.index << " ";
}
cout << endl;
return 0;
}
这里空空如也
有帮助,赞一个