PAT A1062 Talent and Virtue (25分)

题意:德才均大于及格线low的才进行排序,排序的人按种姓分为 :) sages-nobleman-fool man-trash

对于人的类型的排序只需要在结构体中加入一个int type即可,通过这个数字来进行类型排序

AC代码:

//1062 Talent and Virtue (25分) https://pintia.cn/problem-sets/994805342720868352/problems/994805410555346944
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char str[5][10] = { "","trash","fool man","nobleman","sages" };
struct student {
	char id[10];
	int talent;
	int virtue;
	int total;
	int type;//四种类型,从4到1
}stu[100010];
void classify(student *s,int low,int high)
{
	int x = s->talent, y = s->virtue;
	if (x >= high && y >= high)
		s->type = 4;
	else if (y >= high && x < high) s->type = 3;
	else if (x < high && y < high && y >= x) s->type = 2;
	else s->type = 1;
}
bool cmp(student p1, student p2)//分数比较
{
	if (p1.type != p2.type) return p1.type > p2.type;
	else if (p1.total != p2.total) return p1.total > p2.total;
	else if (p1.virtue != p2.virtue) return p1.virtue > p2.virtue;
	else return strcmp(p1.id, p2.id) < 0;
}
int main()
{
	int N, count = 0;
	scanf("%d", &N);
	int low, high;
	scanf("%d%d", &low, &high);
	for (int i = 0; i < N; i++) {
		int t, v;
		char s[10] = { 0 };
		scanf("%s %d %d",s,&v,&t);
		if (t >= low && v >= low) {//过滤掉德或才不及格的人
			strcpy(stu[count].id, s);
			stu[count].talent = t;
			stu[count].virtue = v;
			stu[count].total = t + v;
			classify(stu+count, low, high);
			count++;
		}
	}
	sort(stu, stu + N, cmp);
	printf("%d\n", count);
	for (int i = 0; i < count; i++) {
		printf("%s %d %d\n", stu[i].id, stu[i].virtue, stu[i].talent);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值