1062 Talent and Virtue (25 分)

1062 Talent and Virtue (25 分)

题意

先给出三个数N(成员人数),L(及格线),H(优秀线)
给出一组成员信息,包括id,品德,才能,给这组成员排序。
当该成员品德和才能都不低于H,则该成员分在优秀组
当该成员品德不低于H,才能不低于L,则该成员分在良好组
当该成员品德和才能都低于H,但都不低于L且品德大于才能,则该成员分在中等组。
其他人中品德和才能不低于L,则分在及合组,品德和才能任一低于L则不参与排名。
排名时优先级 优秀组>良好组>中等组>及格组
同组中品德和才能总分越高,排名越前。总分相同,品德分越高越前。品德分相同id越小越靠前。

思路

建立成员信息结构体,包含id,品德,才能,品德和才能总分。对所有成员分组,组内再按规则排序。

代码

#include<stdio.h>
#include<algorithm>

using namespace std;

typedef struct node{
	int id,virtue,talent,total;
}node;

bool cmp(node x,node y)
{
	if(x.total==y.total){
		if(x.virtue==y.virtue){
			return x.id<y.id;
		}else{
			return x.virtue>y.virtue;
		}
	}else{
		return x.total>y.total;
	}
}

node sages[100007],noblemen[100007],fools[100007],others[100007];
	
int main()
{
//	node sages[100007],noblemen[100007],fools[100007],others[100007];
	int n,pass,excellent,x,y,z,count1=0,count2=0,count3=0,count4=0;
	scanf("%d%d%d",&n,&pass,&excellent);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&x,&y,&z);
		if(y>=excellent&&z>=excellent){
			sages[count1].id=x;
			sages[count1].virtue=y;
			sages[count1].talent=z;
			sages[count1].total=y+z;
			count1++;
		}else if(y>=excellent&&z>=pass){
			noblemen[count2].id=x;
			noblemen[count2].virtue=y;
			noblemen[count2].talent=z;
			noblemen[count2].total=y+z;
			count2++;
		}else if(y>=z&&z>=pass){
			fools[count3].id=x;
			fools[count3].virtue=y;
			fools[count3].talent=z;
			fools[count3].total=y+z;
			count3++;
		}else if(y>=pass&&z>=pass){
			others[count4].id=x;
			others[count4].virtue=y;
			others[count4].talent=z;
			others[count4].total=y+z;
			count4++;
		}
	}
	printf("%d\n",count1+count2+count3+count4);
	sort(sages,sages+count1,cmp);
	for(int i=0;i<count1;i++){
		printf("%d %d %d\n",sages[i].id,sages[i].virtue,sages[i].talent);
	}
	sort(noblemen,noblemen+count2,cmp);
	for(int i=0;i<count2;i++){
		printf("%d %d %d\n",noblemen[i].id,noblemen[i].virtue,noblemen[i].talent);
	}
	sort(fools,fools+count3,cmp);
	for(int i=0;i<count3;i++){
		printf("%d %d %d\n",fools[i].id,fools[i].virtue,fools[i].talent);
	}
	sort(others,others+count4,cmp);
	for(int i=0;i<count4;i++){
		printf("%d %d %d\n",others[i].id,others[i].virtue,others[i].talent);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值