链接: PAT (Basic Level) Practice (中文)1015 德才论.
#include <iostream>
#include <queue>
using namespace std;
int H;
class info
{
public:
long long id;
int de, cai, grade;
bool operator()(info a, info b) {
if (a.grade != b.grade)
{
return a.grade < b.grade;
}
else
{
if((a.de + a.cai) != (b.de + b.cai))
return (a.de + a.cai) < (b.de + b.cai);
else if(a.de != b.de)
return a.de < b.de;
else
return a.id > b.id;
}
}
};
int main() {
int N, L;
cin >> N >> L >> H;
priority_queue<info, vector<info>, info> Map;
int num = 0;
info temp;
for (int i = 0; i < N; ++i)
{
cin >> temp.id >> temp.de >> temp.cai;
if (temp.de >= L && temp.cai >= L)
{
if (temp.de >= H && temp.cai >= H)
{
temp.grade = 4;
}
else if (temp.de >= H)
{
temp.grade = 3;
}
else if (temp.de >= temp.cai && temp.de < H)
{
temp.grade = 2;
}
else
{
temp.grade = 1;
}
Map.push(temp);
}
}
cout << Map.size() << endl;
while(!Map.empty())
{
temp = Map.top();
Map.pop();
cout << temp.id << ' ' << temp.de << ' ' << temp.cai << endl;
}
return 0;
}