洛谷P1786帮贡排序

第一遍排序:

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值