蒟蒻求助
查看原帖
蒟蒻求助
398190
Celestial_Intertwine楼主2021/4/26 21:17

此蒟蒻在做一道很水的绿题时遇到了问题,发帖求助 题目链接 p1786 Code

#include<iostream>
#include<algorithm>
using namespace std;

struct node{
	string name,work,now;
	int level,num;//num输入序号 
	long long bg;
}a[120];

bool cmp_bg(node a,node b){//按照帮贡从大到小排序node类 
	return a.bg>b.bg;
} 

int shift(string s){
	if (s=="BangZhu") return 0;
	if (s=="FuBangZhu") return 1;
	if (s=="HuFa") return 2;
	if (s=="ZhangLao") return 3;
	if (s=="TangZhu") return 4;
	if (s=="JingYing") return 5;
	if (s=="BangZhong") return 6;
}

bool cmp2(node x,node y){
	if (shift(x.now)==shift(y.now)){
		if (x.level==y.level) return x.num<y.num;//现职位相等且等级相等,按输入顺序排列
		return x.level>y.level;//等级不等按等级排序
	}
	return shift(x.now)<shift(y.now);//现职位不等按现职位大小排序
}

main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].name>>a[i].work>>a[i].bg>>a[i].level;
		a[i].num=i;
	} 
	sort(a+4,a+n+1,cmp_bg); 
	for (int i=1;i<=n;i++){//按先顺序授予每个人职位
	if (i==1) a[i].now="BangZhu";
	else if (i==2||i==3) a[i].now="FuBangZhu";
	else if (i==4||i==5) a[i].now="HuFa";
	else if (i>=6&&i<=9) a[i].now="ZhangLao";
	else if (i>=10&&i<=16) a[i].now="TangZhu";
	else if (i>=17&&i<=41) a[i].now="JingYing";
	else a[i].now="BangZhong";
	}
	sort(a+4,a+n+1,cmp2);
	for(int i=1;i<=n;i++) cout<<a[i].name<<" "<<a[i].now<<" "<<a[i].level<<endl;
} 


2021/4/26 21:17
加载中...