http://pat.zju.edu.cn/contests/pat-b-practise/1015
#include <stdio.h>
#include <algorithm>
using namespace std;
#define SIZE 1000
typedef struct STU{
int id;
int d;
int c;
int sum;
bool operator < (const STU &A) const{
if( sum != A.sum)
return sum>A.sum;
if( d != A.d)
return d>A.d;
return id<A.id;
}
} S;
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
// freopen("E:\\out.txt", "w", stdout);
#endif
int n, l, h;
while(scanf("%d %d %d", &n,&l,&h)!= EOF){
int i;
S stu;
S _1[SIZE];//4 class
S _2[SIZE];
S _3[SIZE];
S _4[SIZE];
int len1=0, len2=0, len3=0, len4=0;
for(i=0; i<n;i++){
scanf("%d %d %d", &stu.id, &stu.d, &stu.c);
if(stu.d>=h && stu.c>=h){//1 lei
_1[len1].id = stu.id;
_1[len1].d = stu.d;
_1[len1].c = stu.c;
_1[len1].sum= _1[len1].d+_1[len1].c;
len1++;
}else if(stu.d>=h && stu.c<h && stu.c>=l){//2 lei
_2[len2].id = stu.id;
_2[len2].d = stu.d;
_2[len2].c = stu.c;
_2[len2].sum = _2[len2].d+_2[len2].c;
len2++;
}else if(stu.d<h && stu.d>=l && stu.c>=l && stu.c<h && stu.d>=stu.c){//3 lei
_3[len3].id = stu.id;
_3[len3].d = stu.d;
_3[len3].c = stu.c;
_3[len3].sum = _3[len3].c+_3[len3].d;
len3++;
}else if(stu.d>=l && stu.c>=l){
_4[len4].id = stu.id;
_4[len4].d = stu.d;
_4[len4].c = stu.c;
_4[len4].sum=_4[len4].d+_4[len4].c;
len4++;
}
}//归类完毕
/*
printf("%d\n", i);
printf("%d\n", len1);
printf("%d\n", len2);
printf("%d\n", len3);
printf("%d\n", len4);
*/
printf("%d\n", len1+len2+len3+len4);
sort(_1, _1+len1);
for (i=0; i<len1;i++){
printf("%8d %d %d\n", _1[i].id, _1[i].d, _1[i].c);
}
sort(_2, _2+len2);
for (i=0; i<len2;i++){
printf("%8d %d %d\n", _2[i].id, _2[i].d, _2[i].c);
}
sort(_3, _3+len3);
for (i=0; i<len3;i++){
printf("%8d %d %d\n", _3[i].id, _3[i].d, _3[i].c);
}
sort(_4, _4+len4);
for (i=0; i<len4;i++){
printf("%8d %d %d\n", _4[i].id, _4[i].d, _4[i].c);
}
}//while
return 0;
}