PAT (Advanced) 1062. Talent and Virtue (25)

本文介绍了一个使用C++实现的人员选拔程序。该程序通过输入人员的ID、品德分数和才能分数,根据一定的条件筛选出合格的人员,并按类型及总分等条件进行排序输出。涉及C++结构体定义、向量容器应用、条件判断和排序算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

struct Man
{
	int id;
	int virtue;
	int talent;
	int total;
	int type;
};

vector<Man> man;

bool cmp(const Man &a, const Man &b)
{
	if (a.type != b.type)
		return a.type < b.type;
	else
	{
		if (a.total != b.total)
			return a.total > b.total;
		else
		{
			if (a.virtue != b.virtue)
				return a.virtue > b.virtue;
			else
				return a.id < b.id;
		}
	}
}

int main()
{
	int n, l, h;
	cin >> n >> l >> h;
	int id_num, virtue_grade, talent_grade;
	Man tmp;
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d", &id_num, &virtue_grade, &talent_grade);
		//	cin >> id_num >> virtue_grade >> talent_grade;
		if (virtue_grade >= l && talent_grade >= l)
		{
			tmp.total = virtue_grade + talent_grade;
			if (virtue_grade >= h && talent_grade >= h)
				tmp.type = 0;
			else if (virtue_grade >= h && talent_grade < h)
				tmp.type = 1;
			else if (virtue_grade < h && talent_grade < h && virtue_grade >= talent_grade)
				tmp.type = 2;
			else
				tmp.type = 3;
			tmp.id = id_num;
			tmp.virtue = virtue_grade;
			tmp.talent = talent_grade;
			man.push_back(tmp);
		}
	}
	sort(man.begin(), man.end(), cmp);
	vector<Man>::iterator it;
	cout << man.size() << endl;
	for (it = man.begin(); it != man.end(); ++it)
	{
		printf("%08d %d %d\n", it->id, it->virtue, it->talent);
		//	cout << it->id << " " << it->virtue << " " << it->talent << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值