6. Tribute Sorting
Background to the topic
In absi2011's gang, there are a lot of dead numbers. Now absi2011 and the gang leader and others have jointly decided to remove some dead numbers, add in some new numbers, and at the same time encourage people who have a lot of tributes to take a break from the gang.
Title Description
Currently, there is a total of up to one gang leader, two deputy gang leaders, two protectors, four elders, seven hall masters, twenty-five elites, and a number of gang members.
Now absi2011 is going to have to make some adjustments to all the positions of almost everyone in the gang. He's finding this to be a difficult task. So asks you to help him adjust it.
He gives you the following data for each:
His name (no longer than\(30\)), his original position, his tribute, his rank.
He would give the position of Protector to the one with the most tribute, followed by the Elder, and so on.
However, the display of the funfair is not sorted by tribute but by position and rank.
He wants you to derive the list (after he's tweaked the positions) that the final Ledoux displays: position first keyword, rank second keyword.
Note: absi2011 has no authority to adjust the positions of the gang leader and vice leader, including his own (isn't that bullshit...)
He gives them to you in the same order as they were originally given to you (so, with the same rank, the ones that were ahead are now going to be ahead as well, because of the experience level, but experience is omitted here for simplicity's sake.)
input format
First line a positive integer\(n\), indicates the number of gang members in the Star and Moon home.
the following\(n\) The rows are two strings of two integers each, representing each person's name, position, tribute, and rank.
output format
Total output\(n\) Rows, each including the name, position, and rank of the sorted Ledoux display.
Sample #1
Sample Input #1
9
DrangonflyKang BangZhu 100000 66
RenZaiJiangHu FuBangZhu 80000 60
absi2011 FuBangZhu 90000 60
BingQiLingDeYanLei HuFa 89000 58
Lcey HuFa 30000 49
BangYou3 ZhangLao 1000 1
BangYou1 TangZhu 100 40
BangYou2 JingYing 40000 10
BangYou4 BangZhong 400 1
Sample Output #1
DrangonflyKang BangZhu 66
RenZaiJiangHu FuBangZhu 60
absi2011 FuBangZhu 60
BingQiLingDeYanLei HuFa 58
BangYou2 HuFa 10
Lcey ZhangLao 49
BangYou1 ZhangLao 40
BangYou3 ZhangLao 1
BangYou4 ZhangLao 1
draw attention to sth.
Various positions are replaced with Hanyu Pinyin.
If the position is left\(1\) One, and there are\(2\) A person with the same gang tribute will choose the one who was in front to now be elected to this position.
Another:
Gang Name: Star and Moon Home
Master's Honorary Name: Dragonfly Kang
Gang ID: 2685023
Gang level: 4
Number of gangs: 101/110
Gang skills:
Star and Moon Home Profile, welcome to all soybean oils_
[Data range]
insofar as\(10\%\) The data that guarantees the\(n=3\)。
insofar as\(40\%\) data, ensuring that each person's gang tribute is all\(0\)。
insofar as\(100\%\) The data that guarantees the\(3\leq n\leq 110\)The length of each name\(\leq30\),\(0\leq\) Tribute for each\(\leq1000000000\),
\(1\leq\) rank\(\leq 150\)。
The guaranteed position must be\(\texttt{BangZhu}\),\(\texttt{FuBangZhu}\),\(\texttt{HuFa}\),\(\texttt{ZhangLao}\),\(\texttt{TangZhu}\),\(\texttt{JingYing}\),\(\texttt{BangZhong}\) one of
Guaranteed to have a gang leader, guaranteed to have two deputy gang leaders, guaranteed to have a deputy gang leader named absi2011
It is not guaranteed that all positions in the gang will be filled at the beginning, but after sorting and assigning positions please assign senior positions first. For example, if you had one Protector, now you have two.
Ensure that names are not repeated.
[Title source]
absi2011 Authorized Title
Thoughts:
- This question we first clear thinking, we first have to assign new positions to all the people in the gang first, and then according to the new position, rank and number of reordering after the output
Assign new positions to all:
-
According to the conditions given in the question, we reallocate positions to all people: the gang leader, the deputy gang leader does not need to reallocate positions, but for the following people, we need to first look at whether the tribute is the same or not, if it is different, then the one who has a bigger tribute will be in the front, otherwise we compare the serial number, and the one who has a smaller serial number will be in the front, and we need to sort from the guardian only (because our array is counted from the subscript 1, so it is said that we only need to sort from a+4------a+1+n).
-
Defining Structures and Arrays of Structures
struct people {
// original position, name, and new position
string name, zhiwei,xzw.
//The tribute has to be opened long long
long long banggong; long long banggong
long long dengji; int num; int
}a[125].
int n; int
- Sort by tribute, and if the tribute is the same, sort by serial number.
bool compare(people p1, people p2)
{
if ( != ) return >;
else return <;
}
- Sort by tribute and assign new positions.
// Sort the protector and everyone after him.
sort(a + 4, a + 1 + n, compare);
for (int i = 1; i <= n; i++) {
if (i == 1) a[i].xzw = "BangZhu";
else if (i >= 2 && i <= 3) a[i].xzw = "FuBangZhu";
else if (i >= 4 && i <= 5) a[i].xzw = "HuFa";
else if (i >= 6 && i <= 9) a[i].xzw = "ZhangLao";
else if (i >= 10 && i <= 16) a[i].xzw = "TangZhu";
else if (i >= 17 && i <= 41) a[i].xzw = "JingYing";
else a[i].xzw = "BangZhong";
}
- Define a new comparison function for sorting the output position functions, but we have to know, how to go in accordance with the position of the sort? ---- We can define a function that returns a large number for a high position, and compare the numbers they return
//Convert the position into a number, according to the position to facilitate the division of the order, the larger the position, the larger the number
int change(string s)
int change(string s)
else if (s == "HuFa") return 4; else if (s == "ZhangZhu")
else if (s == "JingYing") return 1; else return 0; else
else return 0; }
}
Sequential ordering of new owners
bool compare2(people p1, people p2)
{
if (change() != change()) return change() > change();
else {
if ( != ) return > ;
else {
return < ;
}
}
}
final code
#include<iostream>
#include<algorithm>
using namespace std;
struct people {
string name, zhiwei, xzw;
long long banggong;
long long dengji;
int num;
}a[125];
int n;
bool compare(people p1, people p2)
{
if ( == ) return < ;
else return > ;
}
//Translating jobs into numbers,Facilitates sequencing based on position,larger the position,larger the number
int change(string s)
{
if (s == "BangZhu") return 6;
else if (s == "FuBangZhu") return 5;
else if (s == "HuFa") return 4;
else if (s == "ZhangLao") return 3;
else if (s == "TangZhu") return 2;
else if (s == "JingYing") return 1;
else return 0;
}
bool compare2(people p1, people p2)
{
if (change() != change()) return change() > change();
else {
if ( != ) return > ;
else {
return < ;
}
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].name >> a[i].zhiwei >> a[i].banggong >> a[i].dengji;
a[i].num = i;
}
//arrange in order,The Platoon Protector and all those behind him.
sort(a + 4, a + 1 + n, compare);
for (int i = 1; i <= n; i++) {
if (i == 1) a[i].xzw = "BangZhu";
else if (i >= 2 && i <= 3) a[i].xzw = "FuBangZhu";
else if (i >= 4 && i <= 5) a[i].xzw = "HuFa";
else if (i >= 6 && i <= 9) a[i].xzw = "ZhangLao";
else if (i >= 10 && i <= 16) a[i].xzw = "TangZhu";
else if (i >= 17 && i <= 41) a[i].xzw = "JingYing";
else a[i].xzw = "BangZhong";
}
//Put it in order again.
sort(a + 1, a + 1 + n, compare2);
for (int i = 1; i <= n; i++) {
cout << a[i].name << " " << a[i].xzw << " " << a[i].dengji << endl;
}
return 0;
}