#include <cmath>
#include <vector>
#include <climits>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
class People {
public:
int id;
int virtue;
int talent;
int totalGrade;
int flag = -1; // 4-sage;3-noble;2-fool;1-small;
};
bool compare1062(People p1, People p2) {
if (p1.flag == p2.flag) {
if (p1.totalGrade == p2.totalGrade) {
if (p1.virtue == p2.virtue) {
return p1.id < p2.id;
}
else {
return p1.virtue > p2.virtue;
}
}
else {
return p1.totalGrade > p2.totalGrade;
}
}
else {
return p1.flag > p2.flag;
}
}
int main() {
int N, L, H;
cin >> N >> L >> H;
vector<People> checklist;
while (N--) {
People people;
scanf("%d %d %d", &people.id, &people.virtue, &people.talent);
people.totalGrade = people.virtue + people.talent;
// those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades
if (people.virtue >= H && people.talent >= H) {
people.flag = 4; // sage
}
// Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages"
else if (people.virtue >= H && people.talent < H && people.talent >= L) {
people.flag = 3; // noble
}
// Those with both grades below H, but with virtue not lower than talent are considered as the "fool men"
else if (people.virtue < H && people.virtue >= L && people.talent < H && people.talent >= L && people.virtue >= people.talent) {
people.flag = 2; // fool
}
else if (people.virtue >= L && people.talent >= L) {
// The rest of people whose grades both pass the L line are ranked after the "fool men".
people.flag = 1; // small
}
else {
// only the ones whose grades of talent and virtue are both not below this line will be ranked
}
if (people.flag > 0) checklist.push_back(people);
}
sort(checklist.begin(), checklist.end(), compare1062);
cout << checklist.size() << endl;
for (int i = 0; i < checklist.size(); i++) {
printf("%d %d %d\n", checklist[i].id, checklist[i].virtue, checklist[i].talent);
}
return 0;
}
PAT A1062 Talent and Virtue
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 基金定投直播20年-第1062天-2019/12/31 今日买入:无。 今日卖出:无。 持仓:$50ETF(SH5...