cmp是参考了题解的排序过程是我自己写的,过程应该没有问题
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
struct bongyou {
char name[30];
string posi;
long long con; //帮贡
int grade; //等级
int weight; //职位权重
int old_order; //原来的顺序
} bong[115];
int cnt[7]; //每一个职位的个数(除帮主和副帮主)
int now = 2; //排序时当前排的职位
bool cmp(bongyou x, bongyou y)
{
if (x.con == y.con) return x.old_order < y.old_order; //帮贡相同就用原来的顺序排序
return x.con > y.con;
}
bool cmp3(bongyou x, bongyou y)
{
if (x.weight == y.weight) { //职位相同就按等级
if (x.grade == y.grade) return x.old_order < y.old_order; //等级相同就按原来顺序排序
return x.grade > y.grade; //等级不相同按等级排
}
return x.weight > y.weight; //职位不相同按职位排
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++) {
cin >> bong[i].name >> bong[i].posi >> bong[i].con >> bong[i].grade;
bong[i].old_order = i;
}
sort(bong, bong + n, cmp); //按帮贡排序
for (int i = 0; i < n; i++) {
if (bong[i].posi == "BangZhu") {
bong[i].weight = 7; //职位权重
continue;
}
if (bong[i].posi == "FuBangZhu") {
bong[i].weight = 6;
continue;
}
switch (now) {
case 2:
bong[i].posi = "HuFa";
bong[i].weight = 5;
cnt[now]++;
if (cnt[now] == 2) now++; //如果数量够了就拍下一个职位
break;
case 3:
bong[i].posi = "ZhangLao";
bong[i].weight = 4;
cnt[now]++;
if (cnt[now] == 4) now++;
break;
case 4:
bong[i].posi = "TangZhu";
bong[i].weight = 3;
cnt[now]++;
if (cnt[now] == 7) now++;
break;
case 5:
bong[i].posi = "TangZhu";
bong[i].weight = 2;
cnt[now]++;
if (cnt[now] == 25) now++;
break;
case 6:
bong[i].posi = "BangZhong";
bong[i].weight = 1;
cnt[now]++;
break;
}
}
sort(bong, bong + n, cmp3); //重新排序后根据题目要求排序
for (int i = 0; i < n; i++) { //输出
cout << bong[i].name << " " << bong[i].posi << " " << bong[i].grade << endl;
}
return 0;
}