题目翻译:
按照规则对结构体数组进行排序
题解思路:
模拟即可
代码:
#include<bits/stdc++.h>
using namespace std;
int N, L, H;//排序总数,下限,上限;
struct member {
string ID;
int virtue, talent, sum = 0;
int kind = 5;//0代表没有资格排名,1代表圣人,2代表君子,3代表愚人,4代表小人
member(string id,int v,int t):ID(id),virtue(v),talent(t){
if (virtue < L || talent < L) kind = 0;
else if (virtue >= H && talent >= H) kind = 1;
else if (virtue >= H && talent < H) kind = 2;
else if (virtue < H && talent < H && virtue >= talent) kind = 3;
else kind = 4;
sum = virtue + talent;
}
};
vector<member> members;
bool comp(member a, member b)
{
if (a.kind < b.kind) return true;
else if (a.kind == b.kind){
if (a.sum > b.sum) return true;
else if (a.sum == b.sum){
if (a.virtue > b.virtue) return true;
else if (a.virtue == b.virtue) return a.ID < b.ID;
else return false;
}
else return false;
}
else return false;
}
int main()
{
cin >> N >> L >> H;
for (int i = 0;i < N;i++){
string ID;
int virtue, talent;
cin >> ID >> virtue >> talent;
member temp(ID,virtue,talent);
if (temp.kind) members.push_back(temp);
}
sort(members.begin(), members.end(), comp);
cout << members.size() << endl;
for (auto i : members) cout << i.ID << " " << i.virtue << " " << i.talent << endl;
}
坑点:
无