第一遍排序:
1.帮贡高的在前
2.顺序靠前的在前
第二遍排序:
1.职位高的在前
2.等级高的在前
3.顺序靠前的在前
结构体输入
进行第一遍排序:赋予每个人职务
进行第二遍排序
输出
5:HuFa
9:ZhangLao
16:TangZhu
41:JingYing
注意帮主和副帮主不用排序;
两次sort排序即可;
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<vector>
#include<cmath>
#include<cctype>
#define IOS std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
#define pi acos(-1);
#include<map>
using namespace std;
int n;
string s1="HuFa",s2="ZhangLao",s3="TangZhu",s4="JingYing",s5="BangZhong";
typedef struct node{
string name,job;
int contribution,grade,index;
}node;
node faction[115];
bool cmp1(node a,node b){
if(a.contribution!=b.contribution)return a.contribution>b.contribution;
return a.index<b.index;
}
string tograde(int x){
if(x<=5)return s1;
if(x<=9)return s2;
if(x<=16)return s3;
if(x<=41)return s4;
return s5;
}
int toint(string str){
if(str==s1)return 1;
if(str==s2)return 2;
if(str==s3)return 3;
if(str==s4)return 4;
return 5;
}
bool cmp2(node a,node b){
int tmp1=toint(a.job),tmp2=toint(b.job);
if(tmp1!=tmp2)return tmp1<tmp2;
if(a.grade!=b.grade)return a.grade>b.grade;
return a.index<b.index;
}
void ccin(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>faction[i].name>>faction[i].job>>faction[i].contribution>>faction[i].grade;
faction[i].index=i;
}
}
void work(){
sort(faction+4,faction+1+n,cmp1);注意:i从1开始,需要faction+1+n;
for(int i=4;i<=n;i++){
faction[i].job=tograde(i);
}
sort(faction+4,faction+n+1,cmp2);
for(int i=1;i<=n;i++){
cout<<faction[i].name<<" "<<faction[i].job<<" "<<faction[i].grade<<endl;
}
}
int main(){
IOS;
ccin();
work();
return 0;
}