PAT | A1062 Talent and Virtue

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct People{
	int id;
	int virtue;
	int talent;
};

vector<People> sages;
vector<People> noblemen;
vector<People> foolmen;
vector<People> others;

bool cmp(People a,People b){
	if(a.talent + a.virtue != b.talent + b.virtue)
		return a.talent + a.virtue > b.talent + b.virtue;
	else if(a.virtue != b.virtue)
		return a.virtue > b.virtue;
	else
		return a.id < b.id;
}

// virtue 和 talent >= higher_line 的 -> sages
// virtue >= higher_line && talent < higher_line -> noblemen
// virtue < higher_line && talent < higher_line && virtue >= talent -> foolmen
// virtue >= lower_bound && talent >= lower_bound -> others

int main(){
	int n,lower_bound,higher_line;
	scanf("%d %d %d",&n,&lower_bound,&higher_line);
	for(int i = 0;i < n;i++){
		People temp;
		scanf("%d %d %d",&temp.id,&temp.virtue,&temp.talent);
		if(temp.virtue < lower_bound || temp.talent < lower_bound)
			continue;
		if(temp.virtue >= higher_line && temp.talent >= higher_line){
			sages.push_back(temp);
		}
		else if(temp.virtue >= higher_line && temp.talent < higher_line){
			noblemen.push_back(temp);
		}
		else if(temp.virtue < higher_line && temp.talent < higher_line && temp.virtue >= temp.talent){
			foolmen.push_back(temp);
		}
		else{
			others.push_back(temp);
		}
	}
	sort(sages.begin(),sages.end(),cmp);
	sort(noblemen.begin(),noblemen.end(),cmp);
	sort(foolmen.begin(),foolmen.end(),cmp);
	sort(others.begin(),others.end(),cmp);
	int s = sages.size() + noblemen.size() + foolmen.size() + others.size();
	printf("%d\n",s);
	s = sages.size();
	for(int i = 0;i < s;i++){
		printf("%08d %d %d\n",sages[i].id,sages[i].virtue,sages[i].talent);
	}
	s = noblemen.size();
	for(int i = 0;i < s;i++){
		printf("%08d %d %d\n",noblemen[i].id,noblemen[i].virtue,noblemen[i].talent);
	}
	s = foolmen.size();
	for(int i = 0;i < s;i++){
		printf("%08d %d %d\n",foolmen[i].id,foolmen[i].virtue,foolmen[i].talent);
	}
	s = others.size();
	for(int i = 0;i < s;i++){
		printf("%08d %d %d\n",others[i].id,others[i].virtue,others[i].talent);
	}
	system("pause");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值