30pts,SOS!
查看原帖
30pts,SOS!
730504
lizeyuhello楼主2024/2/25 11:56
#include<bits/stdc++.h>
using namespace std;

struct person//存每个人的信息
{
	char name[50], before[50], now[50];
	int help, level, id;
}a[115];

int n;

bool cmp1(person a, person b)//按帮贡排序
{
	if (a.help == b.help)
		return a.id < b.id;
	return a.help > b.help;
}

int weight(char s[])//求官职大小
{
	if (s[0] == 'B' && s[6] == 'u')
		return 0;
	if (strlen(s) == 9)
		return 1;
	if (strlen(s) == 4)
		return 2;
	if (s[0] == 'Z')
		return 3;
	if (s[0] == 'T')
		return 4;
	if (s[0] == 'J')
		return 5;
	return 6;
}

bool cmp2(person a, person b)//按官职和等级排序
{
	if (weight(a.now) == weight(b.now))
	{
		if (a.level == b.level)
			return a.id < b.id;
		return a.level > b.level;
	}
	return weight(a.now) < weight(b.now);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%s%s%d%d", a[i].name, a[i].before, &a[i].help, &a[i].level);
		a[i].id = i;
		if (weight(a[i].before) == 0)
			a[i].help = INT_MAX;//帮主帮贡无穷
		if (weight(a[i].before) == 1)
			a[i].help = INT_MAX - 114;//副帮主帮贡比帮主小一点
	}
	sort(a + 1, a + n + 1, cmp1);
	for (int i = 1; i <= n; i++)//给予职位
	{
		if (i <= 1)
			strcpy(a[i].now, "BangZhu");
		else if (i <= 3)
			strcpy(a[i].now, "FuBangZhu");
		else if (i <= 5)
			strcpy(a[i].now, "HuFa");
		else if (i <= 9)
			strcpy(a[i].now, "ZhangLao");
		else if (i <= 16)
			strcpy(a[i].now, "TangZhu");
		else if (i <= 41)
			strcpy(a[i].now, "JingYing");
		else
			strcpy(a[i].now, "BangZhong");
	}
	sort(a + 1, a + n + 1, cmp2);
	for (int i = 1; i <= n; i++)//输出
		printf("%s %s %d\n", a[i].name, a[i].now, a[i].level);
 	return 0;
}

2024/2/25 11:56
加载中...