题目链接: https://pintia.cn/problem-sets/994805342720868352/problems/994805410555346944
知识点:容器使用
/****
* 题意:
* 圣人: 天才,品德好
* 君子: 一般,品德好
* 愚人: 普通,普通
* 小人: 追求天才>品德
*
* 输入: N 总人数,
* L:最低质量线:只有不低于这个才能进行排名
* H:只有都高于这个才能称为圣人
* 降序排列
* 顺序:圣人,君子,愚人,小人
* 排序问题
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
struct node
{
int num, virtue, grade;
};
bool cmp(node a, node b)
{
if ((a.virtue + a.grade) != (b.virtue + b.grade))
return (a.virtue + a.grade) > (b.virtue + b.grade);
else if (a.virtue != b.virtue)
return a.virtue > b.virtue;
else
return a.num < b.num;
}
int main(int argc, const char **argv)
{
int n, l, h;
cin >> n >> l >> h;
vector<node> v[4];
node temp;
int total = n;
for (int i = 0; i < n; i++)
{
scanf("%d %d %d", &temp.num, &temp.virtue, &temp.grade);
if (temp.virtue < l || temp.grade < l)
{
total--;
}
else if (temp.virtue >= h && temp.grade >= h)
{
v[0].push_back(temp);
}
else if (temp.virtue >= h && temp.grade < h)
{
v[1].push_back(temp);
}
else if (temp.virtue < h && temp.grade < h && temp.virtue >= temp.grade)
{
v[2].push_back(temp);
}
else
v[3].push_back(temp);
}
printf("%d\n", total);
for (int i = 0; i < 4; i++)
{
sort(v[i].begin(), v[i].end(), cmp);
for (int j = 0; j < v[i].size(); j++)
printf("%d %d %d\n", v[i][j].num, v[i][j].virtue, v[i][j].grade);
}
return 0;
}