结构体排序
简单题
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int n,l,h,m;
struct stu{
int num;
int virtue;
int talent;
int total;
};
stu sage[11000], noble[11000], fool[11000], other[11000];
//vector<stu> sage, noble, fool, other;
bool cmp(stu a, stu b){
if(a.total == b.total){
if(a.virtue == b.virtue) return a.num < b.num;
else return a.virtue > b.virtue;
}
else return a.total > b.total;
}
int main(){
scanf("%d%d%d",&n,&l,&h);
int q = 0, w = 0, e = 0, r = 0;
int sum = 0;
while(n != 0){
int a;
int c, d;
scanf("%d%d%d",&a,&c,&d);
if(c<l || d<l) {
n--;
continue;
}
else{
sum++;
if(c >= h && d >= h){
sage[q].num = a;
sage[q].virtue = c;
sage[q].talent = d;
sage[q].total = c + d;
q++;
}
else if(d <= h && c >= h){
noble[w].num = a;
noble[w].virtue = c;
noble[w].talent = d;
noble[w].total = c + d;
w++;
}
else if(c <= h && d <= h && d <= c){
fool[e].num = a;
fool[e].virtue = c;
fool[e].talent = d;
fool[e].total = c + d;
e++;
}
else {
other[r].num = a;
other[r].virtue = c;
other[r].talent = d;
other[r].total = c + d;
r++;
}
n--;
}
}
printf("%d\n",sum);
sort(sage,sage+q,cmp);
for(int i=0; i<q; i++) printf("%d %d %d\n",sage[i].num,sage[i].virtue,sage[i].talent);
sort(noble,noble+w,cmp);
for(int i=0; i<w; i++) printf("%d %d %d\n",noble[i].num,noble[i].virtue,noble[i].talent);
sort(fool,fool+e,cmp);
for(int i=0; i<e; i++) printf("%d %d %d\n",fool[i].num,fool[i].virtue,fool[i].talent);
sort(other,other+r,cmp);
for(int i=0; i<r; i++) printf("%d %d %d\n",other[i].num,other[i].virtue,other[i].talent);
return 0;
}