power指职位
contribution指帮贡
level即等级
我想的是先按照帮贡排列好之后重新分配职位
完事之后按同职位的等级优先级再次排序
#include <bits/stdc++.h>
using namespace std;
const int N = 115;
string store[115];
struct state
{
string name;
string power;
long long contribution;
int level;
} people[N];
bool comp(state a, state b)
{
return a.contribution > b.contribution;
}
bool comp_2(state a, state b)
{
if (a.power == b.power)
return a.level > b.level;
else
{
return a.contribution > b.contribution;
}
}
int main()
{
int total_people;
cin >> total_people;
for (int i = 0; i < total_people; i++)
{
cin >> people[i].name;
cin >> people[i].power;
cin >> people[i].contribution;
cin >> people[i].level;
}
sort(people + 3, people + total_people, comp);
for (int i = 1; i < 115; i++)
{
if (i <= 2)
{
store[i] = "HuFa";
}
else
{
if (i <= 6)
{
store[i] = "ZhangLao";
}
else
{
if (i <= 13)
{
store[i] = "TangZhu";
}
else
{
if (i <= 38)
{
store[i] = "JingYing";
}
else
{
store[i] = "BangZhong";
}
}
}
}
}
int flag = 1;
for (int i = 0; i < total_people; i++)
{
if (i <= 2)
{
}
else
{
people[i].power = store[flag];
flag++;
}
}
// if (flag <= 2)
// {
// sort(people + 3, people + total_people, comp_2);
// }
// if (flag > 2 && flag <= 6)
// {
// sort(people + 3, people + 3 + 2, comp_2);
// sort(people + 3 + 2, people + total_people, comp_2);
// }
// if (flag > 6 && flag <= 13)
// {
// sort(people + 3, people + 3 + 2, comp_2);
// sort(people + 3 + 2, people + 3 + 2 + 4, comp_2);
// sort(people + 3 + 2 + 4, people + total_people, comp_2);
// }
// if (flag > 13 && flag <= 38)
// {
// sort(people + 3, people + 3 + 2, comp_2);
// sort(people + 3 + 2, people + 3 + 2 + 4, comp_2);
// sort(people + 3 + 2 + 4, people + 3 + 2 + 4 + 7, comp_2);
// sort(people + 3 + 2 + 4 + 7, people + total_people, comp_2);
// }
// if (flag > 38)
// {
// sort(people + 3, people + 3 + 2, comp_2);
// sort(people + 3 + 2, people + 3 + 2 + 4, comp_2);
// sort(people + 3 + 2 + 4, people + 3 + 2 + 4 + 7, comp_2);
// sort(people + 3 + 2 + 4 + 7, people + 3 + 2 + 4 + 7 + 25, comp_2);
// sort(people + 3 + 2 + 4 + 7 + 25, people + total_people, comp_2);
// }
sort(people + 3, people + total_people, comp_2);
for (int i = 0; i < total_people; i++)
{
cout << people[i].name;
cout << " ";
cout << people[i].power << " ";
cout << people[i].level;
cout << endl;
}
return 0;
}