题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1062
德才论:按给定分类,然后进行排序。
// 典型分类排序题
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define SIZE 10000+10
using namespace std;
struct Node
{
int id;
int virtue;
int talent;
int total;
bool operator < (const Node& A) const
{
if(total != A.total)
{
return total > A.total;
}
else if(virtue != A.virtue)
{
return virtue > A.virtue;
}
else
{
return id < A.id;
}
}
};
vector<Node> sage;
vector<Node> noble;
vector<Node> fool;
vector<Node> small;
void output(vector<Node> v)
{
for(int i=0; i<v.size(); i++)
{
printf("%08d %d %d\n", v[i].id, v[i].virtue, v[i].talent);
}
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
#endif
int N, L, H;
// input
scanf("%d%d%d", &N, &L, &H);
while(N-->0)
{
Node t;
scanf("%d%d%d", &t.id, &t.virtue, &t.talent);
t.total = t.virtue + t.talent;
if(t.virtue >= L && t.talent >= L)
{
if(t.virtue >= H && t.talent >= H)
{
sage.push_back(t);
}
else if(t.virtue >= H && t.talent < H)
{
noble.push_back(t);
}
else if(t.virtue < H && t.talent < H && t.virtue >= t.talent)
{
fool.push_back(t);
}
else
{
small.push_back(t);
}
}
}
//output
printf("%d\n", sage.size()+noble.size()+fool.size()+small.size());
sort(sage.begin(), sage.end());
output(sage);
sort(noble.begin(), noble.end());
output(noble);
sort(fool.begin(), fool.end());
output(fool);
sort(small.begin(), small.end());
output(small);
return 0;
}